mirror of
https://gitea.gofwd.group/Forward_Group/ballistic-builder-spring.git
synced 2025-12-06 02:56:44 -05:00
some tweaks for product offers.
This commit is contained in:
@@ -3,6 +3,7 @@ package group.goforward.ballistic.controllers;
|
|||||||
import group.goforward.ballistic.model.Product;
|
import group.goforward.ballistic.model.Product;
|
||||||
import group.goforward.ballistic.model.ProductOffer;
|
import group.goforward.ballistic.model.ProductOffer;
|
||||||
import group.goforward.ballistic.repos.ProductOfferRepository;
|
import group.goforward.ballistic.repos.ProductOfferRepository;
|
||||||
|
import group.goforward.ballistic.web.dto.ProductOfferDto;
|
||||||
import group.goforward.ballistic.repos.ProductRepository;
|
import group.goforward.ballistic.repos.ProductRepository;
|
||||||
import group.goforward.ballistic.web.dto.ProductSummaryDto;
|
import group.goforward.ballistic.web.dto.ProductSummaryDto;
|
||||||
import group.goforward.ballistic.web.mapper.ProductMapper;
|
import group.goforward.ballistic.web.mapper.ProductMapper;
|
||||||
@@ -72,6 +73,25 @@ public class ProductController {
|
|||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{id}/offers")
|
||||||
|
public List<ProductOfferDto> getOffersForProduct(@PathVariable("id") Integer productId) {
|
||||||
|
List<ProductOffer> offers = productOfferRepository.findByProductId(productId);
|
||||||
|
|
||||||
|
return offers.stream()
|
||||||
|
.map(offer -> {
|
||||||
|
ProductOfferDto dto = new ProductOfferDto();
|
||||||
|
dto.setId(offer.getId().toString());
|
||||||
|
dto.setMerchantName(offer.getMerchant().getName());
|
||||||
|
dto.setPrice(offer.getEffectivePrice());
|
||||||
|
dto.setOriginalPrice(offer.getOriginalPrice());
|
||||||
|
dto.setInStock(Boolean.TRUE.equals(offer.getInStock()));
|
||||||
|
dto.setBuyUrl(offer.getBuyUrl());
|
||||||
|
dto.setLastUpdated(offer.getLastSeenAt());
|
||||||
|
return dto;
|
||||||
|
})
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
private ProductOffer pickBestOffer(List<ProductOffer> offers) {
|
private ProductOffer pickBestOffer(List<ProductOffer> offers) {
|
||||||
if (offers == null || offers.isEmpty()) {
|
if (offers == null || offers.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -8,5 +8,8 @@ import java.util.List;
|
|||||||
|
|
||||||
public interface ProductOfferRepository extends JpaRepository<ProductOffer, Integer> {
|
public interface ProductOfferRepository extends JpaRepository<ProductOffer, Integer> {
|
||||||
|
|
||||||
|
List<ProductOffer> findByProductId(Integer productId);
|
||||||
|
|
||||||
|
// Used by the /api/products/gunbuilder endpoint
|
||||||
List<ProductOffer> findByProductIdIn(Collection<Integer> productIds);
|
List<ProductOffer> findByProductIdIn(Collection<Integer> productIds);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package group.goforward.ballistic.web.dto;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
|
||||||
|
public class ProductOfferDto {
|
||||||
|
private String id;
|
||||||
|
private String merchantName;
|
||||||
|
private BigDecimal price;
|
||||||
|
private BigDecimal originalPrice;
|
||||||
|
private boolean inStock;
|
||||||
|
private String buyUrl;
|
||||||
|
private OffsetDateTime lastUpdated;
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMerchantName() {
|
||||||
|
return merchantName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMerchantName(String merchantName) {
|
||||||
|
this.merchantName = merchantName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getPrice() {
|
||||||
|
return price;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrice(BigDecimal price) {
|
||||||
|
this.price = price;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getOriginalPrice() {
|
||||||
|
return originalPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOriginalPrice(BigDecimal originalPrice) {
|
||||||
|
this.originalPrice = originalPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInStock() {
|
||||||
|
return inStock;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInStock(boolean inStock) {
|
||||||
|
this.inStock = inStock;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBuyUrl() {
|
||||||
|
return buyUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBuyUrl(String buyUrl) {
|
||||||
|
this.buyUrl = buyUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OffsetDateTime getLastUpdated() {
|
||||||
|
return lastUpdated;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastUpdated(OffsetDateTime lastUpdated) {
|
||||||
|
this.lastUpdated = lastUpdated;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user