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;
import lombok.Getter;
import com.nisum.ascend.inventory.model.Product;
import java.util.ArrayList;
import java.util.List;
@Getter
@AllArgsConstructor
public class ProductDto {
......@@ -16,14 +19,14 @@ public class ProductDto {
private String brand;
private String category;
private int stock;
private PromotionDto promotion;
private List<PromotionDto> promotions;
public static ProductDto generateDtoFromProduct(Product product) {
// 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 {
public Flux<ProductDto> findAllProducts() {
return productRepository.findAll()
.map(ProductDto::generateDtoFromProduct)
.flatMap(Flux::just);
.map(ProductDto::generateDtoFromProduct);
}
......
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