Skip to content

Commit

Permalink
Product package classes were refactored a little bit
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunagatov committed Jul 23, 2023
1 parent 21c66bb commit 32d6f53
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
import java.math.BigDecimal;

public record PriceDetailsDto(
@NotNull(message = "Price is mandatory")
@DecimalMin(value = "0.0", message = "Price minimum value should be more than 0.0")

@NotNull(message = "Price is the mandatory attribute")
@DecimalMin(value = "0.0", message = "Price minimum value must be more than 0.0")
BigDecimal price,

@NotBlank(message = "Currency is mandatory")
@NotBlank(message = "Currency the mandatory attribute")
@Size(max = 55, message = "Currency length must be less than 55 characters")
String currency
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
import java.util.UUID;

public record ProductInfoDto(
@NotNull(message = "Id is mandatory")
@NotNull(message = "Id is the mandatory attribute")
UUID id,

@NotBlank(message = "Name is mandatory")
@NotBlank(message = "Name is the mandatory attribute")
@Size(max = 100, message = "Name length must be less than 100 characters")
String name,

@NotBlank(message = "Description is mandatory")
@NotBlank(message = "Description is the mandatory attribute")
@Size(max = 1000, message = "Description length must be less than 1000 characters")
String description,

@NotNull(message = "Price details is mandatory")
@NotNull(message = "Price details is the mandatory attribute")
PriceDetailsDto priceDetails
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,25 @@
import java.util.UUID;

public record ProductInfoFullDto(
@NotNull(message = "Id is mandatory")

@NotNull(message = "Id is the mandatory attribute")
UUID id,

@NotBlank(message = "Name is mandatory")
@NotBlank(message = "Name is the mandatory attribute")
@Size(max = 100, message = "Name length must be less than 100 characters")
String name,

@NotBlank(message = "Description is mandatory")
@NotBlank(message = "Description is the mandatory attribute")
@Size(max = 1000, message = "Description length must be less than 1000 characters")
String description,

@NotNull(message = "PriceDetails is mandatory")
@NotNull(message = "PriceDetails is the mandatory attribute")
PriceDetailsDto priceDetails,

@NotNull(message = "Quantity is mandatory")
@NotNull(message = "Quantity is the mandatory attribute")
Integer quantity,

@NotNull(message = "Active is mandatory")
@NotNull(message = "Active is the mandatory attribute")
Boolean active
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public class ProductsEndpoint {
private final ProductInfoDtoConverter productInfoDtoConverter;

@GetMapping("/{id}")
@ResponseBody
public ResponseEntity<ProductInfoDto> getProductInfoById(@PathVariable("id") final String id) {
log.info("Received request to get the ProductInfo with id - {}.", id);
Optional<ProductInfo> ProductInfo = productInfoRepository.findById(Integer.parseInt(id));
Expand All @@ -45,7 +44,6 @@ public ResponseEntity<ProductInfoDto> getProductInfoById(@PathVariable("id") fin
}

@GetMapping
@ResponseBody
public ResponseEntity<Collection<ProductInfoDto>> getAllProducts() {
log.info("Received request to get all ProductInfos");
Collection<ProductInfo> productInfoCollection = productInfoRepository.findAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
Expand All @@ -17,6 +18,7 @@
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "product")
public class ProductInfo {
Expand All @@ -43,16 +45,6 @@ public class ProductInfo {
@Column(name = "active", nullable = false)
private Boolean active;

public ProductInfo(UUID id, String name, String description, BigDecimal price, String currency, Integer quantity, Boolean active) {
this.id = id;
this.name = name;
this.description = description;
this.price = price;
this.currency = currency;
this.quantity = quantity;
this.active = active;
}

@Override
public boolean equals(Object object) {
if (this == object)
Expand Down

0 comments on commit 32d6f53

Please sign in to comment.