Skip to content
Extraits de code Groupes Projets
Valider 161cc64e rédigé par anas elhaddad's avatar anas elhaddad
Parcourir les fichiers

handle restored "live" product status correctly

and fix expiration date for salesession and saleorder
parent 6e0a4939
Branches
1 requête de fusion!126handle restored "live" product status correctly
Pipeline #21258 réussi avec les étapes
in 2 minutes et 12 secondes
## [1.0.79-RELEASE]
### Added
- New features that have been added.
### Changed
- Changes in existing functionality.
### Deprecated
- Soon-to-be removed features.
### Removed
- Features that have been removed.
### Fixed
- handle restored "live" product status correctly.
### Security
- Any security improvements.
## [1.0.78-RELEASE]
### Added
- New features that have been added.
......
......@@ -18,7 +18,7 @@
<dependency>
<groupId>com.marketingconfort</groupId>
<artifactId>mydressin-common</artifactId>
<version>1.0.214-RELEASE</version>
<version>1.0.226-RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
......
......@@ -24,6 +24,7 @@ public class ItemRequestDTO {
private GiftCardDTO giftCardDTO;
private long liveId;
private String ugs;
private Boolean isRestored;
public ItemRequestDTO(Long id, Long quantity, ProductType type) {
this.productId=id;
......
......@@ -17,6 +17,7 @@ public class ProductDetailsCartDTO {
private long quantity;
private double totalPrice;
private ItemSource source;
private Boolean isRestored;
private ItemCartStatus status;
private long sessionOrderId;
}
......@@ -79,7 +79,7 @@ public interface CartRepository extends JpaRepository<Cart, Long>, JpaSpecificat
LocalDateTime endDate,
ItemSource source);
@Query("SELECT c FROM Cart c " +
"WHERE EXISTS (SELECT ic1 FROM c.items ic1 WHERE ic1.status != 'DELETED_BO' AND ic1.source = 'WEB' OR :todayDate < ic1.expirationDate AND ic1.source = 'LIVE') " +
"WHERE EXISTS (SELECT ic1 FROM c.items ic1 WHERE (ic1.status != 'DELETED_WEB' AND ic1.source = 'WEB' ) OR (:todayDate < ic1.expirationDate AND ic1.source = 'LIVE')) " +
" 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))")
......
......@@ -47,9 +47,7 @@ import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.*;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
......@@ -1120,12 +1118,16 @@ public class CartServiceImp implements CartService {
if (item == null) {
return false;
}
boolean isLiveAndNotExpired = ItemSource.LIVE.equals(item.getSource())
&& ZonedDateTime.now(ZoneOffset.UTC).toLocalDateTime().isBefore(item.getExpirationDate());
boolean isNotDeleted = !item.getStatus().equals(ItemCartStatus.DELETED_BO)
&& !(item.getStatus().equals(ItemCartStatus.DELETED_SITE) && item.getSource().equals(ItemSource.WEB));
boolean isNotExpired = Boolean.FALSE.equals(item.isExpired());
boolean isLiveAndNotExpired = !"LIVE".equals(item.getSource())
|| LocalDateTime.now().isBefore(item.getExpirationDate());
return isNotDeleted && isNotExpired && isLiveAndNotExpired;
}
......@@ -1148,6 +1150,7 @@ public class CartServiceImp implements CartService {
detailsDTO.setTotalPrice(price);
detailsDTO.setProductCartDTOS(productCart);
detailsDTO.setStatus(item.getStatus());
detailsDTO.setIsRestored(item.getIsRestored() != null ? item.getIsRestored() : false);
SessionOrder sessionOrderByItemCartId = sessionOrderRepository.findSessionOrderByItemCart_Id(item.getId());
if(sessionOrderByItemCartId!=null){
detailsDTO.setSessionOrderId(sessionOrderByItemCartId.getSaleSession().getId());
......
......@@ -73,6 +73,7 @@ public class ItemCartServiceImp implements ItemCartService {
itemCart.setSource(source);
itemCart.setPayed(false);
itemCart.setExpired(false);
itemCart.setIsRestored(itemRequest.getIsRestored() != null ? itemRequest.getIsRestored() : false);
itemCart.setProductType(itemRequest.getType());
itemCart.setStatus(ItemCartStatus.NOT_CONSULTED);
itemCart.setUgs(itemRequest.getUgs());
......
......@@ -17,6 +17,7 @@ import com.marketingconfort.mydressin.exceptions.SaleSessionExpiredException;
import com.marketingconfort.mydressin.exceptions.SaleSessionNotFoundException;
import com.marketingconfort.mydressin.mappers.SessionOrderMapper;
import com.marketingconfort.mydressin.mappers.SaleSessionMapper;
import com.marketingconfort.mydressin.repositories.ItemCartRepository;
import com.marketingconfort.mydressin.repositories.SaleSessionRepository;
import com.marketingconfort.mydressin.repositories.SessionOrderRepository;
import com.marketingconfort.mydressin.services.*;
......@@ -40,10 +41,8 @@ import org.springframework.beans.factory.annotation.Value;
import java.io.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.ZoneId;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
......@@ -65,7 +64,8 @@ public class SaleSessionServiceImp implements SaleSessionService {
private final UnregisteredCartService unregisteredCartService;
private final SessionOrderRepository sessionOrderRepository;
private final ExternalApiService externalApiService;
private FTPConfig ftpConfig;
private final FTPConfig ftpConfig;
private final ItemCartRepository itemCartRepository;
......@@ -146,7 +146,7 @@ public class SaleSessionServiceImp implements SaleSessionService {
SaleSession saleSession = saleSessionRepository.findById(request.getSessionId())
.orElseThrow(() -> new SaleSessionNotFoundException("Sale session not found for " + request.getSessionId()));
if (saleSession.getExpirationDate().isBefore(LocalDateTime.now())) {
if (saleSession.getExpirationDate().isBefore(ZonedDateTime.now(ZoneOffset.UTC).toLocalDateTime())) {
throw new SaleSessionExpiredException("Sale session has expired for session id");
}
......@@ -163,22 +163,26 @@ public class SaleSessionServiceImp implements SaleSessionService {
Optional<ItemCart> existingItemCart;
if (cart instanceof Cart) {
existingItemCart = ((Cart) cart).getItems().stream()
.filter(item -> item.getProductId().equals(request.getProductId())
&& item.getSource() == ItemSource.LIVE
&& Objects.equals(item.getOrder().getSaleSession().getId(), request.getSessionId())
&& item.getStatus() != ItemCartStatus.DELETED_BO
&& item.getStatus() != ItemCartStatus.DELETED_SITE)
.findFirst();
} else {
existingItemCart = ((UnregisteredCart) cart).getItems().stream()
.filter(item -> item.getProductId().equals(request.getProductId())
&& item.getSource() == ItemSource.LIVE
&& Objects.equals(item.getOrder().getSaleSession().getId(), request.getSessionId())
&& item.getStatus() != ItemCartStatus.DELETED_BO
&& item.getStatus() != ItemCartStatus.DELETED_SITE)
.findFirst();
}
existingItemCart = ((Cart) cart).getItems().stream()
.filter(item -> item.getProductId().equals(request.getProductId())
&& item.getSource() == ItemSource.LIVE
&& Objects.equals(item.getOrder().getSaleSession().getId(), request.getSessionId())
&& item.getStatus() != ItemCartStatus.DELETED_BO
&& item.getStatus() != ItemCartStatus.DELETED_SITE)
.findFirst();
} else {
existingItemCart = ((UnregisteredCart) cart).getItems().stream()
.filter(item -> item.getProductId().equals(request.getProductId())
&& item.getSource() == ItemSource.LIVE
&& Objects.equals(item.getOrder().getSaleSession().getId(), request.getSessionId())
&& item.getStatus() != ItemCartStatus.DELETED_BO
&& item.getStatus() != ItemCartStatus.DELETED_SITE)
.findFirst();
}
ItemCart itemCart;
SessionOrder order;
if (existingItemCart.isPresent()) {
......@@ -189,7 +193,6 @@ public class SaleSessionServiceImp implements SaleSessionService {
order = itemCart.getOrder();
} else {
itemCart = itemCartService.createNewItemCart(request, cart, ItemSource.LIVE);
itemCart.setExpirationDate(saleSession.getExpirationDate());
......@@ -223,7 +226,7 @@ public class SaleSessionServiceImp implements SaleSessionService {
@Override
public SaleSessionDTO updateExpirationDate(Long sessionId, LocalDateTime newExpirationDate) {
if (newExpirationDate.isBefore(LocalDateTime.now())) {
if (newExpirationDate.isBefore(ZonedDateTime.now(ZoneOffset.UTC).toLocalDateTime())) {
throw new IllegalArgumentException("La nouvelle date d'expiration ne peut pas être antérieure à la date actuelle.");
}
......@@ -260,6 +263,10 @@ public class SaleSessionServiceImp implements SaleSessionService {
SaleSession saleSession = saleSessionRepository.findById(sessionId)
.orElseThrow(() -> new SaleSessionNotFoundException("Sale session not found for id: " + sessionId));
saleSession.setStatus("DELETED");
List<SessionOrder> orders = saleSession.getOrders();
for (SessionOrder order : orders) {
order.getItemCart().setStatus(ItemCartStatus.DELETED_BO);
}
saleSessionRepository.save(saleSession);
return true;
}
......@@ -415,13 +422,20 @@ public class SaleSessionServiceImp implements SaleSessionService {
ItemRequestDTO itemRequestDTO = new ItemRequestDTO();
itemRequestDTO.setClientId(sessionOrder.getClientId());
itemRequestDTO.setSessionId(sessionOrder.getSaleSession() != null ? sessionOrder.getSaleSession().getId() : null);
itemRequestDTO.setSessionId(
Optional.ofNullable(sessionOrder.getSaleSession())
.map(SaleSession::getId)
.orElse(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(ItemCartStatus.DELETED_SITE.equals(sessionOrder.getItemCart().getStatus()))
itemRequestDTO.setIsRestored(true);
if (sessionOrder.getItemCart().getProductType() != null && sessionOrder.getItemCart().getProductType().equals(ProductType.GIFT_CARD)) {
itemRequestDTO.setGiftCardDTO(externalApiService.getGiftCardById(sessionOrder.getItemCart().getProductId()));
itemRequestDTO.setUseWebStockForLive(false);
......@@ -430,6 +444,8 @@ public class SaleSessionServiceImp implements SaleSessionService {
itemRequestDTO.setLiveId(sessionOrder.getSaleSession().getLive());
CompletableFuture<SessionOrderDTO> sessionOrderDTO = (sessionOrder.isRegisteredClient()) ? addProductToCartFromLive(itemRequestDTO) : addProductToUnregisteredCartFromLive(itemRequestDTO);
sessionOrderRepository.deleteSessionOrderByOrderId(orderId);
System.out.println("Hello here item cart id " + sessionOrder.getItemCart().getId());
itemCartRepository.deleteById(sessionOrder.getItemCart().getId());
return sessionOrderDTO;
}
......
......@@ -26,6 +26,8 @@ import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
......@@ -151,7 +153,7 @@ public class SessionOrderServiceImp implements SessionOrderService {
SessionOrder order = optionalOrder.get();
if (order.getSaleSession().getExpirationDate().isBefore(LocalDateTime.now())) {
if (order.getSaleSession().getExpirationDate().isBefore(ZonedDateTime.now(ZoneOffset.UTC).toLocalDateTime())) {
throw new SaleSessionExpiredException("Sale session has expired for session id: " + order.getSaleSession().getId());
}
if (order.getStatus() != OrderStatus.EN_ATTENTE) {
......@@ -200,7 +202,7 @@ public class SessionOrderServiceImp implements SessionOrderService {
public boolean deleteOrderById(Long orderId) {
return sessionOrderRepository.findById(orderId)
.map(order -> {
if (order.getSaleSession().getExpirationDate().isBefore(LocalDateTime.now())) {
if (order.getSaleSession().getExpirationDate().isBefore(ZonedDateTime.now(ZoneOffset.UTC).toLocalDateTime())) {
throw new SaleSessionExpiredException("Sale session has expired for session id: " + order.getSaleSession().getId());
}
if (order.getItemCart().getStatus() != ItemCartStatus.DELETED_BO && order.getItemCart().getStatus() != ItemCartStatus.DELETED_SITE) {
......
0% ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter