Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mtpontes committed Oct 20, 2024
2 parents 14a2692 + a1ade92 commit 658cd01
Show file tree
Hide file tree
Showing 28 changed files with 1,159 additions and 345 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public Map<String, Object> swaggerConfig(ServerHttpRequest serverHttpRequest) th
String.format("%s/%s/v3/api-docs", url, service),
"Microservice: " + service.toUpperCase())));
swaggerConfig.put("urls", swaggerUrls);
log.debug("ROTAS: {}", swaggerConfig);
log.debug("ROUTES: {}", swaggerConfig);
return swaggerConfig;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,21 @@
import br.com.ecommerce.products.api.dto.product.DataProductStockDTO;
import br.com.ecommerce.products.api.dto.product.DataStockDTO;
import br.com.ecommerce.products.api.dto.product.EndOfPromotionDTO;
import br.com.ecommerce.products.api.dto.product.SchedulePromotionDTO;
import br.com.ecommerce.products.api.dto.product.SchedulePromotionResponseDTO;
import br.com.ecommerce.products.api.dto.product.UpdatePriceDTO;
import br.com.ecommerce.products.api.dto.product.UpdateProductDTO;
import br.com.ecommerce.products.api.dto.product.UpdateProductImagesResponseDTO;
import br.com.ecommerce.products.api.dto.product.UpdateProductPriceResponseDTO;
import br.com.ecommerce.products.api.dto.product.UpdateProductResponseDTO;
import br.com.ecommerce.products.api.dto.product.UpdatePromotionalPriceDTO;
import br.com.ecommerce.products.api.openapi.IAdminProductController;
import br.com.ecommerce.products.business.service.ProductService;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@AllArgsConstructor
@RestController
@RequestMapping("/admin/products")
Expand Down Expand Up @@ -69,24 +74,40 @@ public ResponseEntity<DataProductStockDTO> updateStock(
@PutMapping("/{productId}/prices")
public ResponseEntity<UpdateProductPriceResponseDTO> updatePrice(
@PathVariable Long productId,
@RequestBody UpdatePriceDTO dto
@RequestBody @Valid UpdatePriceDTO dto
) {
return ResponseEntity.ok(service.updateProductPrice(productId, dto));
}

@PutMapping("/{productId}/prices/switch-to-promotional")
public ResponseEntity<UpdateProductPriceResponseDTO> switchCurrentPriceToPromotionalPrice(
@PutMapping("/{productId}/prices/promotion")
public ResponseEntity<UpdateProductPriceResponseDTO> updatePromotionalPrice(
@PathVariable Long productId,
@RequestBody @Valid UpdatePromotionalPriceDTO dto
) {
return ResponseEntity.ok(service.updateProductPricePromotional(productId, dto));
}

@PutMapping("/{productId}/prices/promotion/start")
public ResponseEntity<UpdateProductPriceResponseDTO> iniciatePromotion(
@PathVariable Long productId,
@RequestBody @Valid EndOfPromotionDTO requestBody
) {
return ResponseEntity.ok(service.switchCurrentPriceToPromotional(productId, requestBody.getEndOfPromotion()));
return ResponseEntity.ok(service.startPromotionImediatly(productId, requestBody.getEndPromotion()));
}

@PutMapping("/{productId}/prices/promotion/schedule")
public ResponseEntity<SchedulePromotionResponseDTO> schedulePromotion(
@PathVariable Long productId,
@RequestBody @Valid SchedulePromotionDTO requestBody
) {
return ResponseEntity.ok(service.schedulePromotion(productId, requestBody));
}

@PutMapping("/{productId}/prices/switch-to-original")
public ResponseEntity<UpdateProductPriceResponseDTO> switchCurrentPriceToOriginalPrice(
@PutMapping("/{productId}/prices/promotion/end")
public ResponseEntity<UpdateProductPriceResponseDTO> finalizePromotion(
@PathVariable Long productId
) {
return ResponseEntity.ok(service.switchCurrentPriceToOriginal(productId));
return ResponseEntity.ok(service.closePromotion(productId));
}

@PatchMapping("/{productId}/images")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ public class CompletePriceDataDTO {
private BigDecimal promotionalPrice;
private boolean onPromotion;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm")
private LocalDateTime endOfPromotion;
private LocalDateTime startPromotion;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm")
private LocalDateTime endPromotion;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.time.LocalDateTime;

import jakarta.validation.constraints.FutureOrPresent;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
Expand All @@ -13,5 +14,6 @@
public class EndOfPromotionDTO {

@NotNull
private LocalDateTime endOfPromotion;
@FutureOrPresent
private LocalDateTime endPromotion;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package br.com.ecommerce.products.api.dto.product;

import java.time.LocalDateTime;

import jakarta.validation.constraints.Future;
import jakarta.validation.constraints.FutureOrPresent;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
@AllArgsConstructor
public class SchedulePromotionDTO {

@FutureOrPresent
@NotNull
private LocalDateTime start;

@Future
@NotNull
private LocalDateTime end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package br.com.ecommerce.products.api.dto.product;

import br.com.ecommerce.products.infra.entity.product.Price;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Getter
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class SchedulePromotionResponseDTO {

private Long id;
private String name;
private Price price;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ public class SimplePriceDataDTO implements Serializable {
private BigDecimal currentPrice;
private BigDecimal originalPrice;
private boolean onPromotion;
private LocalDateTime endOfPromotion;
private LocalDateTime startPromotion;
private LocalDateTime endPromotion;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public class StockWriteOffDTO {

public StockWriteOffDTO(Long productId, Integer unit) {
this.productId = productId;
this.unit = Math.negateExact(unit);
this.unit = unit > 0 ? Math.negateExact(unit) : unit;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.math.BigDecimal;

import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
Expand All @@ -13,6 +14,6 @@
public class UpdatePriceDTO {

@NotNull
private BigDecimal originalPrice;
private BigDecimal promotionalPrice;
@Min(value = 0, message = "Price cannot be equal to or less than zero")
private BigDecimal price;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package br.com.ecommerce.products.api.dto.product;

import java.math.BigDecimal;

import jakarta.validation.constraints.Min;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
@AllArgsConstructor
public class UpdatePromotionalPriceDTO {

@Min(value = 0, message = "Price cannot be equal to or less than zero")
private BigDecimal price;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@
public class PriceMapper {

public Price toPrice(UpdatePriceDTO data) {
return Optional.ofNullable(data)
.map(p -> new Price(p.getOriginalPrice(), data.getPromotionalPrice()))
.orElse(null);
return new Price(data.getPrice());
}

public Price toPriceWithPromotionalPrice(Price origin, UpdatePriceDTO data) {
Price price = new Price(origin.getOriginalPrice());
price.setPromotionalPrice(data.getPrice());
return price;
}

public CompletePriceDataDTO toCompletePriceDataDTO(Price data) {
Expand All @@ -25,7 +29,8 @@ public CompletePriceDataDTO toCompletePriceDataDTO(Price data) {
p.getOriginalPrice(),
p.getPromotionalPrice(),
p.isOnPromotion(),
p.getEndOfPromotion()))
p.getStartPromotion(),
p.getEndPromotion()))
.orElse(null);
}

Expand All @@ -35,7 +40,8 @@ public SimplePriceDataDTO toSimplePriceDataDTO(Price data) {
p.getCurrentPrice(),
p.getOriginalPrice(),
data.isOnPromotion(),
data.getEndOfPromotion()))
data.getStartPromotion(),
data.getEndPromotion()))
.orElse(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import br.com.ecommerce.products.api.dto.product.DataProductPriceDTO;
import br.com.ecommerce.products.api.dto.product.DataStockDTO;
import br.com.ecommerce.products.api.dto.product.InternalProductDataDTO;
import br.com.ecommerce.products.api.dto.product.SchedulePromotionResponseDTO;
import br.com.ecommerce.products.api.dto.product.SimplePriceDataDTO;
import br.com.ecommerce.products.api.dto.product.UpdateProductImagesResponseDTO;
import br.com.ecommerce.products.api.dto.product.UpdateProductPriceResponseDTO;
Expand Down Expand Up @@ -102,4 +103,8 @@ public DataProductPriceDTO toProductPriceDTO(Product data) {
.map(p -> new DataProductPriceDTO(p.getId(), p.getPrice().getCurrentPrice()))
.orElse(null);
}

public SchedulePromotionResponseDTO toSchedulePromotionResponseDTO(Product data) {
return new SchedulePromotionResponseDTO(data.getId(), data.getName(), data.getPrice());
}
}
Loading

0 comments on commit 658cd01

Please sign in to comment.