diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f5bee398895c4dd60d0c8d45d0ad461b54047f3..685be22b6683f69dba64608eaa63c3ff59e74162 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,32 @@ +## [1.0.74-RELEASE] +### Added +- MYD-739/Fix List with sale sessions stats +- Add delete item functionality in back office and display sale session ID + + +### Changed +- Changes in existing functionality. + +### Deprecated +- Soon-to-be removed features. + +### Removed +- Features that have been removed. + +### Fixed +- fix item count +- Restor a sale session fixed + +### Security +- Any security improvements. + ## [1.0.73-RELEASE] ### Added - MYD-739/Fix List with sale sessions stats +- Add delete item functionality in back office and display sale session ID +- Enhance item filtering by excluding deleted items based on status and source + + ### Changed - Changes in existing functionality. @@ -13,6 +39,7 @@ ### Fixed - fix item count +- Restor a sale session fixed ### Security - Any security improvements. diff --git a/pom.xml b/pom.xml index 479dafb26ee5ff45ad71ea51837f6a5c063a8c1a..21dc75834b95fa61716872dfd1768cc425654ecd 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ </parent> <groupId>com.marketingconfort</groupId> <artifactId>mydressin-cart-service</artifactId> - <version>1.0.54-SNAPSHOT</version> + <version>1.0.54-RELEASE</version> <name>mydressin-cart-service</name> <description>Mydressin cart Service</description> <properties> @@ -18,7 +18,7 @@ <dependency> <groupId>com.marketingconfort</groupId> <artifactId>mydressin-common</artifactId> - <version>1.0.206-RELEASE</version> + <version>1.0.212-RELEASE</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> diff --git a/src/main/java/com/marketingconfort/mydressin/dtos/ProductDetailsCartDTO.java b/src/main/java/com/marketingconfort/mydressin/dtos/ProductDetailsCartDTO.java index 9c05b5c46acc01960d813dc3728c3860cd1e2396..7dff50d08d4f26fab93e5f635f06ae5f56d3f503 100644 --- a/src/main/java/com/marketingconfort/mydressin/dtos/ProductDetailsCartDTO.java +++ b/src/main/java/com/marketingconfort/mydressin/dtos/ProductDetailsCartDTO.java @@ -1,6 +1,7 @@ package com.marketingconfort.mydressin.dtos; import com.marketingconfort.mydressin.common.cart.dtos.ProductCartDTO; +import com.marketingconfort.mydressin.common.cart.enumurations.ItemCartStatus; import com.marketingconfort.mydressin.common.cart.enumurations.ItemSource; import lombok.*; @@ -16,4 +17,6 @@ public class ProductDetailsCartDTO { private long quantity; private double totalPrice; private ItemSource source; + private ItemCartStatus status; + private long sessionOrderId; } diff --git a/src/main/java/com/marketingconfort/mydressin/mappers/CartMapper.java b/src/main/java/com/marketingconfort/mydressin/mappers/CartMapper.java index 45412e4fc2cdb1ad18bf3aaf7378b286ba763d49..95855caeef1ee1afcfb13a852e9e5abebc3bfa59 100644 --- a/src/main/java/com/marketingconfort/mydressin/mappers/CartMapper.java +++ b/src/main/java/com/marketingconfort/mydressin/mappers/CartMapper.java @@ -60,14 +60,9 @@ 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(itemCarts.size()); + clientCartDTO.setItemsCount(cart.getItems().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 71eecf3b25b2bf51fd7f5e648a1f258ab539be4d..ce6b5141806e4dbe9a58400ba4511022699efa22 100644 --- a/src/main/java/com/marketingconfort/mydressin/repositories/CartRepository.java +++ b/src/main/java/com/marketingconfort/mydressin/repositories/CartRepository.java @@ -76,9 +76,8 @@ public interface CartRepository extends JpaRepository<Cart, Long>, JpaSpecificat List<Object[]> findActiveClientsCountByDay(LocalDateTime startDate, LocalDateTime endDate, ItemSource source); - @Query("SELECT c FROM Cart c " + - "WHERE EXISTS (SELECT ic1 FROM c.items ic1 WHERE ic1.status != 'DELETED_SITE' AND ic1.status != 'DELETED_BO' ) " + + "WHERE EXISTS (SELECT ic1 FROM c.items ic1 WHERE ic1.status != 'DELETED_BO' ) " + " AND LOWER(c.status) = 'open' " + " 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))") diff --git a/src/main/java/com/marketingconfort/mydressin/repositories/SessionOrderRepository.java b/src/main/java/com/marketingconfort/mydressin/repositories/SessionOrderRepository.java index 06ea98b7bb9615982aba1fefbf5ffbbeb7bba484..3e8ae6c563d596d1341f8f7a2f6e47ff82d140f0 100644 --- a/src/main/java/com/marketingconfort/mydressin/repositories/SessionOrderRepository.java +++ b/src/main/java/com/marketingconfort/mydressin/repositories/SessionOrderRepository.java @@ -21,4 +21,5 @@ public interface SessionOrderRepository extends JpaRepository<SessionOrder,Long> void updateItemCartExpirationDateBySaleSessionId(@Param("sessionId") Long sessionId, @Param("expirationDate") LocalDateTime expirationDate); List<SessionOrder> findAll(); + SessionOrder findSessionOrderByItemCart_Id(Long id); } 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 c6aca4a51acc36f25c97c79b71cb1d54069c77f3..605612961aee832affb43fcf2509f0c69336c1ca 100644 --- a/src/main/java/com/marketingconfort/mydressin/services/impl/CartServiceImp.java +++ b/src/main/java/com/marketingconfort/mydressin/services/impl/CartServiceImp.java @@ -16,6 +16,7 @@ import com.marketingconfort.mydressin.common.cart.enumurations.OrderStatus; import com.marketingconfort.mydressin.common.cart.enumurations.Status; import com.marketingconfort.mydressin.common.cart.models.Cart; import com.marketingconfort.mydressin.common.cart.models.ItemCart; +import com.marketingconfort.mydressin.common.cart.models.SessionOrder; import com.marketingconfort.mydressin.common.constant.urlServiceConstant.NameUri; import com.marketingconfort.mydressin.common.constant.urlServiceConstant.NameUrl; import com.marketingconfort.mydressin.common.constant.urlServiceConstant.Path.AddonsServicePath; @@ -29,6 +30,7 @@ import com.marketingconfort.mydressin.exceptions.InsufficientBalanceException; import com.marketingconfort.mydressin.mappers.CartMapper; import com.marketingconfort.mydressin.mappers.ProductDTOMapper; import com.marketingconfort.mydressin.repositories.CartRepository; +import com.marketingconfort.mydressin.repositories.SessionOrderRepository; import com.marketingconfort.mydressin.services.*; import com.marketingconfort.starter.core.exceptions.TechnicalException; import com.marketingconfort.starter.core.services.MCRestTemplateService; @@ -65,9 +67,10 @@ public class CartServiceImp implements CartService { private final NameUrl nameUrl; private final ExternalApiService externalApiService; private final PromoCodeUtilService promoCodeUtilService; + private final SessionOrderRepository sessionOrderRepository; public CartServiceImp(CartRepository cartRepository, ProductStockService productStockService, CartMapper cartMapper, CartCountConfigService cartCountConfigService, - MCRestTemplateService mcRestTemplateService, NameUrl nameUrl, ExternalApiService externalApiService, PromoCodeUtilService promoCodeUtilService) { + MCRestTemplateService mcRestTemplateService, NameUrl nameUrl, ExternalApiService externalApiService, PromoCodeUtilService promoCodeUtilService, SessionOrderRepository sessionOrderRepository) { this.cartRepository = cartRepository; this.productStockService = productStockService; this.cartMapper = cartMapper; @@ -76,6 +79,7 @@ public class CartServiceImp implements CartService { this.nameUrl = nameUrl; this.externalApiService = externalApiService; this.promoCodeUtilService = promoCodeUtilService; + this.sessionOrderRepository = sessionOrderRepository; } @@ -1092,11 +1096,15 @@ public class CartServiceImp implements CartService { } }); } + List<ProductDetailsCartDTO> productDetailsCartDTOS = cart.getItems().stream() .map(item -> mapItemToProductDetails(item, productMap)) .filter(Objects::nonNull) + .filter(item -> !item.getStatus().equals(ItemCartStatus.DELETED_BO)) + .filter(item -> !(item.getStatus().equals(ItemCartStatus.DELETED_SITE) && item.getSource().equals(ItemSource.WEB))) .toList(); + cartDTO.setSubTotalPrice(productDetailsCartDTOS.stream() .mapToDouble(ProductDetailsCartDTO::getTotalPrice) .sum()); @@ -1119,11 +1127,16 @@ public class CartServiceImp implements CartService { ? productCart.getPromoPrice() * item.getQuantity() : productCart.getRegularPrice() * item.getQuantity(); ProductDetailsCartDTO detailsDTO = new ProductDetailsCartDTO(); - detailsDTO.setItemId(item.getProductId()); + detailsDTO.setItemId(item.getId()); detailsDTO.setQuantity(item.getQuantity()); detailsDTO.setSource(item.getSource()); detailsDTO.setTotalPrice(price); detailsDTO.setProductCartDTOS(productCart); + detailsDTO.setStatus(item.getStatus()); + SessionOrder sessionOrderByItemCartId = sessionOrderRepository.findSessionOrderByItemCart_Id(item.getId()); + if(sessionOrderByItemCartId!=null){ + detailsDTO.setSessionOrderId(sessionOrderByItemCartId.getSaleSession().getId()); + } return detailsDTO; } diff --git a/src/main/java/com/marketingconfort/mydressin/services/impl/SaleSessionServiceImp.java b/src/main/java/com/marketingconfort/mydressin/services/impl/SaleSessionServiceImp.java index 2bcc9063e872192c3f2c3fd4cf785e09a13734ec..c5e5fa66564ed586cfc52bbd21023af1c614ffe4 100644 --- a/src/main/java/com/marketingconfort/mydressin/services/impl/SaleSessionServiceImp.java +++ b/src/main/java/com/marketingconfort/mydressin/services/impl/SaleSessionServiceImp.java @@ -74,9 +74,8 @@ public class SaleSessionServiceImp implements SaleSessionService { public SaleSessionDTO getSaleSessionStatistics(SaleSession saleSession) { SaleSessionDTO saleSessionDTO = saleSessionMapper.toDTO(saleSession); - List<ItemCartStatus> excludedStatuses = Arrays.asList( - ItemCartStatus.DELETED_BO, - ItemCartStatus.DELETED_SITE + List<ItemCartStatus> excludedStatuses = List.of( + ItemCartStatus.DELETED_BO ); Long totalOrderProducts = saleSessionRepository.getTotalOrderProducts(saleSessionDTO.getId()); Integer totalClientsCount = saleSessionRepository.getTotalClientsCount(saleSessionDTO.getId()); @@ -240,7 +239,6 @@ public class SaleSessionServiceImp implements SaleSessionService { public boolean deleteSaleSessionById(Long sessionId) { SaleSession saleSession = saleSessionRepository.findById(sessionId) .orElseThrow(() -> new SaleSessionNotFoundException("Sale session not found for id: " + sessionId)); - saleSession.setStatus("DELETED"); saleSessionRepository.save(saleSession); return true; @@ -252,7 +250,7 @@ public class SaleSessionServiceImp implements SaleSessionService { public SaleSessionDTO restockSaleSession(Long sessionId) { SaleSession saleSession = saleSessionRepository.findById(sessionId) .orElseThrow(() -> new SaleSessionNotFoundException("Sale session not found for id: " + sessionId)); - saleSession.setStatus(null); + saleSession.setStatus("ACTIVE"); SaleSession updatedSaleSession = saleSessionRepository.save(saleSession); return saleSessionMapper.toDTO(updatedSaleSession); }