Commit 56207eb6 authored by Ben Anderson's avatar Ben Anderson

Added DTOs for product and promotion

parent 760d7c93
package dto;public class ProductDto { package dto;
import lombok.AllArgsConstructor;
import lombok.Getter;
import model.Product;
@Getter
@AllArgsConstructor
public class ProductDto {
private String sku;
private String upc;
private String prodName;
private String prodDesc;
private float price;
private String prodImgUrl;
private String brand;
private String category;
private int stock;
private PromotionDto promotion;
public static ProductDto generateDtoFromProduct(Product product) {
// TODO: Fetch the product's promotion from the Promotions service
PromotionDto promotion = new PromotionDto();
return new ProductDto(product.getSku(), product.getUpc(), product.getProdName(), product.getProdDesc(), product.getPrice(), product.getProdImgUrl(), product.getBrand(), product.getCategory(), product.getAvailableStock(), promotion);
}
} }
package dto;public class PromotionDto { package dto;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public class PromotionDto {
private String promotionId;
private String productSku;
private String discountPercentage;
private String minimumQuantity;
public PromotionDto() {}
} }
package service; package service;
import dto.ProductDto;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
import repository.ProductRepository; import repository.ProductRepository;
@Service @Service
public class ProductService { public class ProductService {
@Autowired @Autowired
ProductRepository productRepository; ProductRepository productRepository;
public Flux<ProductDto> testDto() {
return productRepository.findAll()
.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