Commit c8d096a6 authored by Khai Yuan ​Liew's avatar Khai Yuan ​Liew

[AFP-55] Modify ProductDto and ProductService

parent 8c054aca
...@@ -4,6 +4,9 @@ import lombok.AllArgsConstructor; ...@@ -4,6 +4,9 @@ import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import com.nisum.ascend.inventory.model.Product; import com.nisum.ascend.inventory.model.Product;
import java.util.ArrayList;
import java.util.List;
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public class ProductDto { public class ProductDto {
...@@ -16,14 +19,14 @@ public class ProductDto { ...@@ -16,14 +19,14 @@ public class ProductDto {
private String brand; private String brand;
private String category; private String category;
private int stock; private int stock;
private PromotionDto promotion; private List<PromotionDto> promotions;
public static ProductDto generateDtoFromProduct(Product product) { public static ProductDto generateDtoFromProduct(Product product) {
// TODO: Fetch the product's promotion from the Promotions com.nisum.ascend.inventory.service // TODO: Fetch the product's promotion from the Promotions com.nisum.ascend.inventory.service
PromotionDto promotion = new PromotionDto(); List<PromotionDto> promotions = new ArrayList<>();
return new ProductDto(product.getSku(), product.getUpc(), product.getProductName(), product.getProductDescription(), product.getPrice(), product.getProductImageUrl(), product.getBrand(), product.getCategory(), product.getAvailableStock(), promotion); return new ProductDto(product.getSku(), product.getUpc(), product.getProductName(), product.getProductDescription(), product.getPrice(), product.getProductImageUrl(), product.getBrand(), product.getCategory(), product.getAvailableStock(), promotions);
} }
} }
...@@ -14,8 +14,7 @@ public class ProductService { ...@@ -14,8 +14,7 @@ public class ProductService {
public Flux<ProductDto> findAllProducts() { public Flux<ProductDto> findAllProducts() {
return productRepository.findAll() return productRepository.findAll()
.map(ProductDto::generateDtoFromProduct) .map(ProductDto::generateDtoFromProduct);
.flatMap(Flux::just);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment