diff --git a/CHANGELOG.md b/CHANGELOG.md index 48c3c1abe587c31c99fc74d36e96a1b97e0e497c..312db3fa747ce87915678a3164fb26ded664a4ac 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 e156a0a192511991cf0085b8e8408828293570ae..49e56123164171e053a2627687f6c9b7c97797ac 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 4f2c6cd8349442dcda7acea178d650747ab9357c..9dbd0cccacf647b68a915ce4ef29edde259bd6cd 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 9959efd5d6f363a7382f494b636941e7b40b46d0..005fec8a5a0649be94a360837e033440c9f0c7de 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 21041c2277379522bd38ebcae6571122147b0732..afc4c54d844440267b43efc1e866910235b42e28 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 {