diff --git a/CHANGELOG.md b/CHANGELOG.md index fb1c3639abbde4ca9f875f743036cd488a8ea47d..2179125cadc8dafe1381f6acf75dad7ab42297a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,22 @@ ### Removed - Features that have been removed. +### Fixed +- fix search by client. + +- ## [1.0.70-RELEASE] +### Added +- Added a method to verify cart consistency with the database. + +### Changed +- change common version + +### Deprecated +- Soon-to-be removed features. + +### Removed +- Features that have been removed. + ### Fixed - Fix save promo code usage history. diff --git a/src/main/java/com/marketingconfort/mydressin/mappers/CartMapper.java b/src/main/java/com/marketingconfort/mydressin/mappers/CartMapper.java index 2329e4f02df7af64d0050f04907ec232a2a723aa..45412e4fc2cdb1ad18bf3aaf7378b286ba763d49 100644 --- a/src/main/java/com/marketingconfort/mydressin/mappers/CartMapper.java +++ b/src/main/java/com/marketingconfort/mydressin/mappers/CartMapper.java @@ -2,6 +2,8 @@ package com.marketingconfort.mydressin.mappers; import com.marketingconfort.mydressin.common.cart.enumurations.ItemCartStatus; import com.marketingconfort.mydressin.common.cart.models.Cart; +import com.marketingconfort.mydressin.common.cart.models.ItemCart; +import com.marketingconfort.mydressin.common.stockmanagement.enumurations.ProductType; import com.marketingconfort.mydressin.dtos.CartDTO; import com.marketingconfort.mydressin.dtos.ClientCartDTO; import com.marketingconfort.mydressin.services.ExternalApiService; @@ -11,6 +13,7 @@ import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; import java.math.BigDecimal; +import java.util.List; import java.util.stream.Collectors; @Service @@ -57,10 +60,14 @@ public class CartMapper { public ClientCartDTO cartToClientCartDTO(Cart cart) { + List<ItemCart> itemCarts = cart.getItems() + .stream() + .filter(itemCart -> itemCart.getStatus()!=ItemCartStatus.DELETED_SITE && itemCart.getStatus()!=ItemCartStatus.DELETED_BO ) + .toList(); + ClientCartDTO clientCartDTO = new ClientCartDTO(); clientCartDTO.setId(cart.getId()); - clientCartDTO.setItemsCount(cart.getItemsCount()); - clientCartDTO.setSubTotalPrice(cart.getSubTotalPrice()); + clientCartDTO.setItemsCount(itemCarts.size()); return clientCartDTO; } diff --git a/src/main/java/com/marketingconfort/mydressin/repositories/CartRepository.java b/src/main/java/com/marketingconfort/mydressin/repositories/CartRepository.java index a36a3752a5974969c43c61074b12218dab2ff8da..a73c5d9eb30358314f94c4a8665a0ca5160cec8d 100644 --- a/src/main/java/com/marketingconfort/mydressin/repositories/CartRepository.java +++ b/src/main/java/com/marketingconfort/mydressin/repositories/CartRepository.java @@ -78,10 +78,10 @@ public interface CartRepository extends JpaRepository<Cart, Long>, JpaSpecificat ItemSource source); @Query("SELECT c FROM Cart c " + - "WHERE EXISTS (SELECT ic1 FROM c.items ic1 WHERE ic1.status != 'DELETED_SITE' ) " + + "WHERE EXISTS (SELECT ic1 FROM c.items ic1 WHERE ic1.status != 'DELETED_SITE' AND ic1.status != 'DELETED_BO' ) " + " AND LOWER(c.status) = 'open' " + - " AND (0L in :clientIds OR c.clientId IN :clientIds) " + - " AND (0L in :productIds OR EXISTS (SELECT ic2 FROM c.items ic2 WHERE ic2.productId IN :productIds))") + " AND ((-1L) in :clientIds OR c.clientId IN :clientIds) " + + " AND ((-1L) in :productIds OR EXISTS (SELECT ic2 FROM c.items ic2 WHERE ic2.productId IN :productIds))") Page<Cart> getCartClientPage(@Param("clientIds") List<Long> clientIds, @Param("productIds") List<Long> productIds, Pageable pageable); diff --git a/src/main/java/com/marketingconfort/mydressin/services/impl/CartServiceImp.java b/src/main/java/com/marketingconfort/mydressin/services/impl/CartServiceImp.java index bfae46a3e9c14d3ecd565006c11d2f072a7ab1d8..5e2813fce162fb885b7a3b5a68c317e2b02f4b0b 100644 --- a/src/main/java/com/marketingconfort/mydressin/services/impl/CartServiceImp.java +++ b/src/main/java/com/marketingconfort/mydressin/services/impl/CartServiceImp.java @@ -994,10 +994,10 @@ public class CartServiceImp implements CartService { .filter(Objects::nonNull) .collect(Collectors.toList()); if (clientIds.isEmpty()) { - clientIds = List.of(0L); + clientIds = List.of(-1L); } if (productIds.isEmpty()) { - productIds = List.of(0L); + productIds = List.of(-1L); } Map<Long, ClientDTO> clientMap = clients.stream() .collect(Collectors.toMap(ClientDTO::getUid, Function.identity(), (a, b) -> a)); @@ -1035,7 +1035,11 @@ public class CartServiceImp implements CartService { List<ProductDetailsCartDTO> productDetailsCartDTOS = cart.getItems().stream() .map(item -> mapItemToProductDetails(item, productMap)) .filter(Objects::nonNull) - .collect(Collectors.toList()); + .toList(); + + cartDTO.setSubTotalPrice(productDetailsCartDTOS.stream() + .mapToDouble(ProductDetailsCartDTO::getTotalPrice) + .sum()); cartDTO.setClientDTO(clientDTO); cartDTO.setProductDetailsCartDTOS(productDetailsCartDTOS); return cartDTO;