|
7 | 7 | import dev.nmarulo.depensaapp.app.users.UserRepository;
|
8 | 8 | import dev.nmarulo.depensaapp.commons.exception.NotFoundException;
|
9 | 9 | import dev.nmarulo.depensaapp.commons.service.BasicServiceImp;
|
| 10 | +import dev.nmarulo.depensaapp.commons.util.BigDecimalUtil; |
| 11 | +import dev.nmarulo.depensaapp.commons.util.IntegerUtil; |
10 | 12 | import lombok.Getter;
|
11 | 13 | import lombok.RequiredArgsConstructor;
|
12 | 14 | import org.apache.commons.lang3.StringUtils;
|
@@ -41,7 +43,27 @@ public FindByIdShoppingListRes findById(Long id, User user) {
|
41 | 43 | throw new NotFoundException(getLocalMessage().getMessage("error.record-not-exist"));
|
42 | 44 | }
|
43 | 45 |
|
44 |
| - return ShoppingListMapper.toFindByIdShoppingListRes(findById.get()); |
| 46 | + final var shoppingList = findById.get(); |
| 47 | + final var response = ShoppingListMapper.toFindByIdShoppingListRes(shoppingList); |
| 48 | + final var totalUnitsPerProducts = IntegerUtil.newAtomicReference(response.getTotalUnitsPerProducts()); |
| 49 | + final var totalSelectedProducts = IntegerUtil.newAtomicReference(response.getTotalSelectedProducts()); |
| 50 | + final var totalPriceSelectedProducts = BigDecimalUtil.newAtomicReference(response.getTotalPriceSelectedProducts()); |
| 51 | + |
| 52 | + shoppingList.getProductHasShoppingList() |
| 53 | + .forEach(value -> { |
| 54 | + if (value.isSelected()) { |
| 55 | + totalSelectedProducts.accumulateAndGet(1, Integer::sum); |
| 56 | + totalPriceSelectedProducts.accumulateAndGet(value.getTotalPrice(), BigDecimal::add); |
| 57 | + } |
| 58 | + |
| 59 | + totalUnitsPerProducts.accumulateAndGet(value.getUnitsPerProduct(), Integer::sum); |
| 60 | + }); |
| 61 | + |
| 62 | + response.setTotalUnitsPerProducts(totalUnitsPerProducts.get()); |
| 63 | + response.setTotalSelectedProducts(totalSelectedProducts.get()); |
| 64 | + response.setTotalPriceSelectedProducts(totalPriceSelectedProducts.get()); |
| 65 | + |
| 66 | + return response; |
45 | 67 | }
|
46 | 68 |
|
47 | 69 | public FindByIdProductShoppingListRest findByIdProduct(Integer id, Long productId, User user) {
|
|
0 commit comments