mirror of
https://gitea.gofwd.group/Forward_Group/ballistic-builder-spring.git
synced 2026-01-20 16:51:03 -05:00
fixing the dto to serve build product names etc.
This commit is contained in:
@@ -15,6 +15,8 @@ import group.goforward.battlbuilder.web.dto.BuildFeedCardDto;
|
||||
import group.goforward.battlbuilder.web.dto.BuildItemDto;
|
||||
import group.goforward.battlbuilder.web.dto.BuildSummaryDto;
|
||||
import group.goforward.battlbuilder.web.dto.UpdateBuildRequest;
|
||||
import group.goforward.battlbuilder.repos.ProductRepository;
|
||||
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -41,11 +43,13 @@ public class BuildServiceImpl implements BuildService {
|
||||
private final BuildItemRepository buildItemRepository;
|
||||
private final ProductOfferRepository productOfferRepository;
|
||||
private final CurrentUserService currentUserService;
|
||||
private final ProductRepository productRepository;
|
||||
|
||||
public BuildServiceImpl(
|
||||
BuildRepository buildRepository,
|
||||
BuildProfileRepository buildProfileRepository,
|
||||
BuildItemRepository buildItemRepository,
|
||||
ProductRepository productRepository,
|
||||
ProductOfferRepository productOfferRepository,
|
||||
CurrentUserService currentUserService
|
||||
) {
|
||||
@@ -54,6 +58,7 @@ public class BuildServiceImpl implements BuildService {
|
||||
this.buildItemRepository = buildItemRepository;
|
||||
this.productOfferRepository = productOfferRepository;
|
||||
this.currentUserService = currentUserService;
|
||||
this.productRepository = productRepository;
|
||||
}
|
||||
|
||||
// ---------------------------
|
||||
@@ -145,7 +150,11 @@ public class BuildServiceImpl implements BuildService {
|
||||
}
|
||||
|
||||
List<BuildItem> items = buildItemRepository.findByBuild_Id(build.getId());
|
||||
return toBuildDto(build, items);
|
||||
|
||||
BuildDto dto = toBuildDto(build, items);
|
||||
hydrateBuildDtoItems(dto); // 👈 STEP 2: call it here
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
// ---------------------------
|
||||
@@ -183,6 +192,51 @@ public class BuildServiceImpl implements BuildService {
|
||||
return toBuildDto(saved, items);
|
||||
}
|
||||
|
||||
private void hydrateBuildDtoItems(BuildDto dto) {
|
||||
if (dto == null || dto.getItems() == null || dto.getItems().isEmpty()) return;
|
||||
|
||||
Set<Integer> productIds = dto.getItems().stream()
|
||||
.map(BuildItemDto::getProductId)
|
||||
.filter(Objects::nonNull)
|
||||
.map(Integer::valueOf)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
if (productIds.isEmpty()) return;
|
||||
|
||||
Map<Integer, group.goforward.battlbuilder.model.Product> productsById =
|
||||
productRepository.findAllById(productIds).stream()
|
||||
.collect(Collectors.toMap(
|
||||
group.goforward.battlbuilder.model.Product::getId,
|
||||
p -> p
|
||||
));
|
||||
|
||||
Map<Integer, BigDecimal> bestPriceByProductId = loadBestPrices(productIds);
|
||||
|
||||
for (BuildItemDto item : dto.getItems()) {
|
||||
if (item == null || item.getProductId() == null) continue;
|
||||
|
||||
Integer pid = Integer.valueOf(item.getProductId());
|
||||
var p = productsById.get(pid);
|
||||
|
||||
if (p != null) {
|
||||
item.setProductName(p.getName());
|
||||
item.setProductBrand(
|
||||
p.getBrand() != null ? p.getBrand().getName() : null
|
||||
);
|
||||
|
||||
String img = p.getBattlImageUrl() != null
|
||||
? p.getBattlImageUrl()
|
||||
: p.getMainImageUrl();
|
||||
|
||||
item.setProductImageUrl(img);
|
||||
}
|
||||
|
||||
item.setBestPrice(bestPriceByProductId.get(pid));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ---------------------------
|
||||
// Update build (Vault edit save)
|
||||
// PUT /api/v1/builds/me/{uuid}
|
||||
@@ -306,11 +360,6 @@ public class BuildServiceImpl implements BuildService {
|
||||
: null
|
||||
);
|
||||
|
||||
// optional for now
|
||||
it.setProductName(null);
|
||||
it.setProductBrand(null);
|
||||
it.setProductImageUrl(null);
|
||||
|
||||
return it;
|
||||
})
|
||||
.toList();
|
||||
|
||||
Reference in New Issue
Block a user