From e0389281a957497b08a7cdaf8afce56084cb8e9e Mon Sep 17 00:00:00 2001 From: anasElhaddad <anas.elhaddad@marketingconfort.com> Date: Fri, 9 May 2025 10:14:00 +0000 Subject: [PATCH] add order restoration --- CHANGELOG.md | 19 ++++++++++ .../mydressin/constants/Paths.java | 5 +++ .../controllers/SaleSessionController.java | 10 +++++ .../services/SaleSessionService.java | 2 + .../services/impl/SaleSessionServiceImp.java | 37 ++++++++++++++++++- 5 files changed, 72 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48c3c1a..312db3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,22 @@ +## [1.0.77-RELEASE] +### Added +- add order restoration + +### Changed +- Changes in existing functionality. + +### Deprecated +- Soon-to-be removed features. + +### Removed +- Features that have been removed. + +### Fixed +- Any bug fixes. + +### Security +- Any security improvements. + ## [1.0.76-RELEASE] ### Added - add isExpired condition to cart pagination diff --git a/src/main/java/com/marketingconfort/mydressin/constants/Paths.java b/src/main/java/com/marketingconfort/mydressin/constants/Paths.java index e156a0a..49e5612 100644 --- a/src/main/java/com/marketingconfort/mydressin/constants/Paths.java +++ b/src/main/java/com/marketingconfort/mydressin/constants/Paths.java @@ -31,4 +31,9 @@ public class Paths { public static final String COUNT_TYPE_SALE_SESSION = "/count-type"; public static final String DELETED_SALE_SESSION_PAGE = "/deleted/page"; public static final String DELETED_COUNT_TYPE_SALE_SESSION = "/deleted/count-type"; + + public static final String RESTORE_ORDER = "/restore/{orderId}"; + + + } diff --git a/src/main/java/com/marketingconfort/mydressin/controllers/SaleSessionController.java b/src/main/java/com/marketingconfort/mydressin/controllers/SaleSessionController.java index 4f2c6cd..9dbd0cc 100644 --- a/src/main/java/com/marketingconfort/mydressin/controllers/SaleSessionController.java +++ b/src/main/java/com/marketingconfort/mydressin/controllers/SaleSessionController.java @@ -9,6 +9,7 @@ import com.marketingconfort.mydressin.exceptions.ProductOutOfStockException; import com.marketingconfort.mydressin.exceptions.SaleSessionExpiredException; import com.marketingconfort.mydressin.exceptions.SaleSessionNotFoundException; import com.marketingconfort.mydressin.services.SaleSessionService; +import com.marketingconfort.starter.core.exceptions.FunctionalException; import lombok.AllArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.format.annotation.DateTimeFormat; @@ -66,6 +67,8 @@ public class SaleSessionController { } + + @PostMapping("/addProductToUnregisteredCartFromLive") @PreAuthorize("@securityCustomExpressions.isClientTrusted(#requestAuthorization)") public CompletableFuture<ResponseEntity<?>> addProductToUnregisteredCartFromLive( @@ -205,5 +208,12 @@ public class SaleSessionController { return saleSessionService.getDeletedTypeCount(name, type, startDate, endDate); } + + @PutMapping(Paths.RESTORE_ORDER) + public ResponseEntity<CompletableFuture<SessionOrderDTO>> restoreOrder(@PathVariable Long orderId) throws FunctionalException { + return ResponseEntity.ok(saleSessionService.restoreSaleSessionDetails(orderId)); + + } + } diff --git a/src/main/java/com/marketingconfort/mydressin/services/SaleSessionService.java b/src/main/java/com/marketingconfort/mydressin/services/SaleSessionService.java index 9959efd..005fec8 100644 --- a/src/main/java/com/marketingconfort/mydressin/services/SaleSessionService.java +++ b/src/main/java/com/marketingconfort/mydressin/services/SaleSessionService.java @@ -6,6 +6,7 @@ import com.marketingconfort.mydressin.dtos.SaleSessionDTO; import com.marketingconfort.mydressin.dtos.SessionOrderDTO; import com.marketingconfort.mydressin.dtos.ItemRequestDTO; import com.marketingconfort.mydressin.exceptions.SaleSessionExpiredException; +import com.marketingconfort.starter.core.exceptions.FunctionalException; import org.springframework.data.domain.Page; @@ -41,4 +42,5 @@ public interface SaleSessionService { List<String[]> getDeletedTypeCount(String name , String type, Date startDate, Date endDate); void exportYesterdaySaleSessions(); + CompletableFuture<SessionOrderDTO> restoreSaleSessionDetails(Long oderId) throws FunctionalException; } 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 21041c2..afc4c54 100644 --- a/src/main/java/com/marketingconfort/mydressin/services/impl/SaleSessionServiceImp.java +++ b/src/main/java/com/marketingconfort/mydressin/services/impl/SaleSessionServiceImp.java @@ -1,11 +1,13 @@ package com.marketingconfort.mydressin.services.impl; +import com.marketingconfort.mydressin.common.cart.dtos.GiftCardDTO; import com.marketingconfort.mydressin.common.cart.dtos.ProductStockDTO; import com.marketingconfort.mydressin.common.cart.dtos.ProductStockRequestDTO; import com.marketingconfort.mydressin.common.cart.enumurations.ItemCartStatus; import com.marketingconfort.mydressin.common.cart.enumurations.ItemSource; import com.marketingconfort.mydressin.common.cart.enumurations.OrderStatus; import com.marketingconfort.mydressin.common.cart.models.*; +import com.marketingconfort.mydressin.common.stockmanagement.enumurations.ProductType; import com.marketingconfort.mydressin.config.FTPConfig; import com.marketingconfort.mydressin.dtos.SaleSessionDTO; import com.marketingconfort.mydressin.dtos.SessionOrderDTO; @@ -18,6 +20,7 @@ import com.marketingconfort.mydressin.mappers.SaleSessionMapper; import com.marketingconfort.mydressin.repositories.SaleSessionRepository; import com.marketingconfort.mydressin.repositories.SessionOrderRepository; import com.marketingconfort.mydressin.services.*; +import com.marketingconfort.starter.core.exceptions.FunctionalException; import com.opencsv.CSVWriter; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -61,6 +64,7 @@ public class SaleSessionServiceImp implements SaleSessionService { private final SessionOrderService sessionOrderService; private final UnregisteredCartService unregisteredCartService; private final SessionOrderRepository sessionOrderRepository; + private final ExternalApiService externalApiService; private FTPConfig ftpConfig; @@ -325,7 +329,7 @@ public class SaleSessionServiceImp implements SaleSessionService { return stringList; } - @Scheduled(cron = "0 0 7 * * ?") + @Scheduled(cron = "0 0 * * * ?") @Override public void exportYesterdaySaleSessions() { LocalDate yesterday = LocalDate.now().minusDays(1); @@ -403,6 +407,37 @@ public class SaleSessionServiceImp implements SaleSessionService { } } + @Override + @Transactional + public CompletableFuture<SessionOrderDTO> restoreSaleSessionDetails(Long orderId) throws FunctionalException { + SessionOrder sessionOrder = orderRepository.findById(orderId) + .orElseThrow(() -> new FunctionalException("Order not found")); + + ItemRequestDTO itemRequestDTO = new ItemRequestDTO(); + itemRequestDTO.setClientId(sessionOrder.getClientId()); + + itemRequestDTO.setSessionId(sessionOrder.getSaleSession() != null ? sessionOrder.getSaleSession().getId() : null); + itemRequestDTO.setProductId(sessionOrder.getItemCart().getProductId()); + itemRequestDTO.setQuantity(sessionOrder.getItemCart().getQuantity()); + itemRequestDTO.setType(sessionOrder.getItemCart().getProductType()); + itemRequestDTO.setUgs(sessionOrder.getItemCart().getUgs()); + itemRequestDTO.setUseWebStockForLive(true); + + + if (sessionOrder.getItemCart().getProductType() != null && sessionOrder.getItemCart().getProductType().equals(ProductType.GIFT_CARD)) { + itemRequestDTO.setGiftCardDTO(externalApiService.getGiftCardById(sessionOrder.getItemCart().getProductId())); + itemRequestDTO.setUseWebStockForLive(false); + + } + + itemRequestDTO.setLiveId(sessionOrder.getSaleSession().getLive()); + + CompletableFuture<SessionOrderDTO> sessionOrderDTO = (sessionOrder.isRegisteredClient()) ? addProductToCartFromLive(itemRequestDTO) : addProductToUnregisteredCartFromLive(itemRequestDTO); + orderRepository.deleteById(orderId); + + return sessionOrderDTO; + } + private void uploadFileToFTPServer(String fileName, byte[] fileData) { FTPClient ftpClient = new FTPClient(); try { -- GitLab