Skip to content
Extraits de code Groupes Projets
Valider f4d965c7 rédigé par hamza.elbakkouri's avatar hamza.elbakkouri
Parcourir les fichiers

MYS-739/fix sales sessions details

parents 9fb947f0 3b0f0dbe
Branches
1 requête de fusion!114MYD-739/Fix List with sale sessions stats
## [1.0.72-RELEASE]
### Added ### Added
- New features that have been added. - MYD-628/add pagination, sort and search for deleted sale session
### Changed
- Changes in existing functionality.
### Deprecated
- Soon-to-be removed features.
### Removed
- Features that have been removed.
### Fixed
- fix item count
### Security
- Any security improvements.
## [1.0.71-RELEASE]
### Added
- MYD-628/add pagination, sort and search for sale session
### Changed ### Changed
- Changes in existing functionality. - Changes in existing functionality.
......
...@@ -27,4 +27,8 @@ public class Paths { ...@@ -27,4 +27,8 @@ public class Paths {
public static final String ADD_TO_CART_TRENDS = "/add-to-cart-trends"; public static final String ADD_TO_CART_TRENDS = "/add-to-cart-trends";
public static final String CART_COUNT = "/cart-count"; public static final String CART_COUNT = "/cart-count";
public static final String THEORETICAL_AMOUNT = "/theoretical-amount"; public static final String THEORETICAL_AMOUNT = "/theoretical-amount";
public static final String SALE_SESSION_PAGE = "/page";
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";
} }
package com.marketingconfort.mydressin.controllers; package com.marketingconfort.mydressin.controllers;
import com.marketingconfort.mydressin.common.cart.models.SaleSession; import com.marketingconfort.mydressin.common.cart.models.SaleSession;
import com.marketingconfort.mydressin.constants.Paths;
import com.marketingconfort.mydressin.dtos.SaleSessionDTO; import com.marketingconfort.mydressin.dtos.SaleSessionDTO;
import com.marketingconfort.mydressin.dtos.SessionOrderDTO; import com.marketingconfort.mydressin.dtos.SessionOrderDTO;
import com.marketingconfort.mydressin.dtos.ItemRequestDTO; import com.marketingconfort.mydressin.dtos.ItemRequestDTO;
...@@ -9,12 +10,15 @@ import com.marketingconfort.mydressin.exceptions.SaleSessionExpiredException; ...@@ -9,12 +10,15 @@ import com.marketingconfort.mydressin.exceptions.SaleSessionExpiredException;
import com.marketingconfort.mydressin.exceptions.SaleSessionNotFoundException; import com.marketingconfort.mydressin.exceptions.SaleSessionNotFoundException;
import com.marketingconfort.mydressin.services.SaleSessionService; import com.marketingconfort.mydressin.services.SaleSessionService;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
...@@ -22,7 +26,6 @@ import java.util.concurrent.CompletableFuture; ...@@ -22,7 +26,6 @@ import java.util.concurrent.CompletableFuture;
@RestController @RestController
@RequestMapping(value = "/api/cart", method = RequestMethod.OPTIONS) @RequestMapping(value = "/api/cart", method = RequestMethod.OPTIONS)
@AllArgsConstructor @AllArgsConstructor
public class SaleSessionController { public class SaleSessionController {
private final SaleSessionService saleSessionService; private final SaleSessionService saleSessionService;
...@@ -146,5 +149,61 @@ public class SaleSessionController { ...@@ -146,5 +149,61 @@ public class SaleSessionController {
SaleSessionDTO updatedSession = saleSessionService.restockSaleSession(sessionId); SaleSessionDTO updatedSession = saleSessionService.restockSaleSession(sessionId);
return ResponseEntity.ok(updatedSession); return ResponseEntity.ok(updatedSession);
} }
@GetMapping(Paths.SALE_SESSION_PAGE)
@PreAuthorize("@securityCustomExpressions.isClientTrusted(#requestAuthorization)")
public Page<SaleSessionDTO> getSaleSessionsPage(
@RequestParam(required = false) String name,
@RequestParam(required = false) String type,
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date startDate,
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date endDate,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "10") int size,
@RequestParam(defaultValue = "id") String sortBy,
@RequestParam(defaultValue = "ASC") String sortDir,
@RequestHeader String requestAuthorization) {
return saleSessionService.getSaleSessionsPage(name, type, startDate, endDate, page, size, sortBy, sortDir);
}
@GetMapping(Paths.COUNT_TYPE_SALE_SESSION)
@PreAuthorize("@securityCustomExpressions.isClientTrusted(#requestAuthorization)")
public List<String[]> getStatusCount(
@RequestParam(required = false) String name,
@RequestParam(required = false) String type,
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date startDate,
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date endDate,
@RequestHeader String requestAuthorization) {
return saleSessionService.getTypeCount(name, type, startDate, endDate);
}
@GetMapping(Paths.DELETED_SALE_SESSION_PAGE)
@PreAuthorize("@securityCustomExpressions.isClientTrusted(#requestAuthorization)")
public Page<SaleSessionDTO> getDeletedSaleSessionsPage(
@RequestParam(required = false) String name,
@RequestParam(required = false) String type,
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date startDate,
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date endDate,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "10") int size,
@RequestParam(defaultValue = "id") String sortBy,
@RequestParam(defaultValue = "ASC") String sortDir,
@RequestHeader String requestAuthorization) {
return saleSessionService.getDeletedSaleSessionsPage(name, type, startDate, endDate, page, size, sortBy, sortDir);
}
@GetMapping(Paths.DELETED_COUNT_TYPE_SALE_SESSION)
@PreAuthorize("@securityCustomExpressions.isClientTrusted(#requestAuthorization)")
public List<String[]> getDeletedStatusCount(
@RequestParam(required = false) String name,
@RequestParam(required = false) String type,
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date startDate,
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date endDate,
@RequestHeader String requestAuthorization) {
return saleSessionService.getDeletedTypeCount(name, type, startDate, endDate);
}
} }
...@@ -2,12 +2,15 @@ package com.marketingconfort.mydressin.repositories; ...@@ -2,12 +2,15 @@ package com.marketingconfort.mydressin.repositories;
import com.marketingconfort.mydressin.common.cart.enumurations.ItemCartStatus; import com.marketingconfort.mydressin.common.cart.enumurations.ItemCartStatus;
import com.marketingconfort.mydressin.common.cart.models.SaleSession; import com.marketingconfort.mydressin.common.cart.models.SaleSession;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Date;
import java.util.List; import java.util.List;
@Repository @Repository
...@@ -71,4 +74,50 @@ public interface SaleSessionRepository extends JpaRepository<SaleSession, Long> ...@@ -71,4 +74,50 @@ public interface SaleSessionRepository extends JpaRepository<SaleSession, Long>
Long getTotalPaidProducts(@Param("sessionId") Long sessionId); Long getTotalPaidProducts(@Param("sessionId") Long sessionId);
List<SaleSession> findByStartedDateBetween(LocalDateTime startDate, LocalDateTime endDate); List<SaleSession> findByStartedDateBetween(LocalDateTime startDate, LocalDateTime endDate);
@Query("SELECT sl FROM SaleSession sl WHERE " +
"(:name IS NULL OR :name = '' OR LOWER(sl.name) LIKE LOWER(CONCAT('%', :name, '%'))) " +
"AND (:type IS NULL OR :type = '' OR LOWER(sl.type) like LOWER(CONCAT('%', :type,'%')))" +
"AND ( CAST(:startDate as string) IS NULL OR CAST(sl.startedDate as date) BETWEEN :startDate AND :endDate)" +
"AND sl.status != 'DELETED' ")
Page<SaleSession> getSaleSessionsPage(@Param("type") String type,
@Param("name") String name ,
@Param("startDate") Date startDate ,
@Param("endDate") Date endDate ,
Pageable pageable);
@Query("SELECT sl.type, COUNT(sl) FROM SaleSession sl WHERE " +
"(:name IS NULL OR :name = '' OR LOWER(sl.name) LIKE LOWER(CONCAT('%', :name, '%'))) " +
"AND (:type IS NULL OR :type = '' OR LOWER(sl.type) like LOWER(CONCAT('%', :type,'%')))" +
"AND ( CAST(:startDate as string) IS NULL OR CAST(sl.startedDate as date) BETWEEN :startDate AND :endDate)" +
"AND sl.status != 'DELETED' " +
"GROUP BY sl.type")
List<Object[]> getTypeCount(@Param("type") String type,
@Param("name") String name ,
@Param("startDate") Date startDate ,
@Param("endDate") Date endDate);
@Query("SELECT sl FROM SaleSession sl WHERE " +
"(:name IS NULL OR :name = '' OR LOWER(sl.name) LIKE LOWER(CONCAT('%', :name, '%'))) " +
"AND (:type IS NULL OR :type = '' OR LOWER(sl.type) like LOWER(CONCAT('%', :type,'%')))" +
"AND ( CAST(:startDate as string) IS NULL OR CAST(sl.startedDate as date) BETWEEN :startDate AND :endDate)" +
"AND sl.status = 'DELETED' ")
Page<SaleSession> getSaleSessionsDeletedPage(@Param("type") String type,
@Param("name") String name ,
@Param("startDate") Date startDate ,
@Param("endDate") Date endDate ,
Pageable pageable);
@Query("SELECT sl.type, COUNT(sl) FROM SaleSession sl WHERE " +
"(:name IS NULL OR :name = '' OR LOWER(sl.name) LIKE LOWER(CONCAT('%', :name, '%'))) " +
"AND (:type IS NULL OR :type = '' OR LOWER(sl.type) like LOWER(CONCAT('%', :type,'%')))" +
"AND ( CAST(:startDate as string) IS NULL OR CAST(sl.startedDate as date) BETWEEN :startDate AND :endDate)" +
"AND sl.status = 'DELETED' " +
"GROUP BY sl.type")
List<Object[]> getDeletedTypeCount(@Param("type") String type,
@Param("name") String name ,
@Param("startDate") Date startDate ,
@Param("endDate") Date endDate);
} }
...@@ -6,10 +6,12 @@ import com.marketingconfort.mydressin.dtos.SaleSessionDTO; ...@@ -6,10 +6,12 @@ import com.marketingconfort.mydressin.dtos.SaleSessionDTO;
import com.marketingconfort.mydressin.dtos.SessionOrderDTO; import com.marketingconfort.mydressin.dtos.SessionOrderDTO;
import com.marketingconfort.mydressin.dtos.ItemRequestDTO; import com.marketingconfort.mydressin.dtos.ItemRequestDTO;
import com.marketingconfort.mydressin.exceptions.SaleSessionExpiredException; import com.marketingconfort.mydressin.exceptions.SaleSessionExpiredException;
import org.springframework.data.domain.Page;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
...@@ -30,4 +32,11 @@ public interface SaleSessionService { ...@@ -30,4 +32,11 @@ public interface SaleSessionService {
SaleSessionDTO updateSaleSessionDetails(Long sessionId, String newName, String newDescription); SaleSessionDTO updateSaleSessionDetails(Long sessionId, String newName, String newDescription);
boolean deleteSaleSessionById(Long sessionId); boolean deleteSaleSessionById(Long sessionId);
SaleSessionDTO restockSaleSession(Long sessionId); SaleSessionDTO restockSaleSession(Long sessionId);
Page<SaleSessionDTO> getSaleSessionsPage(String name , String type, Date startDate, Date endDate,
int page, int size, String sortBy, String order);
List<String[]> getTypeCount(String name , String type, Date startDate, Date endDate);
Page<SaleSessionDTO> getDeletedSaleSessionsPage(String name , String type, Date startDate, Date endDate,
int page, int size, String sortBy, String order);
List<String[]> getDeletedTypeCount(String name , String type, Date startDate, Date endDate);
} }
...@@ -20,16 +20,17 @@ import com.marketingconfort.mydressin.repositories.SessionOrderRepository; ...@@ -20,16 +20,17 @@ import com.marketingconfort.mydressin.repositories.SessionOrderRepository;
import com.marketingconfort.mydressin.services.*; import com.marketingconfort.mydressin.services.*;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Arrays; import java.util.*;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -255,4 +256,59 @@ public class SaleSessionServiceImp implements SaleSessionService { ...@@ -255,4 +256,59 @@ public class SaleSessionServiceImp implements SaleSessionService {
SaleSession updatedSaleSession = saleSessionRepository.save(saleSession); SaleSession updatedSaleSession = saleSessionRepository.save(saleSession);
return saleSessionMapper.toDTO(updatedSaleSession); return saleSessionMapper.toDTO(updatedSaleSession);
} }
@Override
public Page<SaleSessionDTO> getSaleSessionsPage(String name, String type, Date startDate, Date endDate, int page, int size, String sortBy, String sortDir) {
if("createdAt".equals(sortBy))
sortBy = "id";
Sort.Direction direction = Sort.Direction.fromString(sortDir);
Pageable pageable = PageRequest.of(page, size, Sort.by(direction, sortBy));
return saleSessionRepository.getSaleSessionsPage(type,name,startDate,endDate,pageable)
.map(saleSessionMapper::toDTO);
}
@Override
public List<String[]> getTypeCount(String name, String type, Date startDate, Date endDate) {
return convertObjectListToStringList(saleSessionRepository.getTypeCount(type, name, startDate, endDate));
}
@Override
public Page<SaleSessionDTO> getDeletedSaleSessionsPage(String name, String type, Date startDate, Date endDate, int page, int size, String sortBy, String sortDir) {
if("createdAt".equals(sortBy))
sortBy = "id";
Sort.Direction direction = Sort.Direction.fromString(sortDir);
Pageable pageable = PageRequest.of(page, size, Sort.by(direction, sortBy));
return saleSessionRepository.getSaleSessionsDeletedPage(type,name,startDate,endDate,pageable)
.map(saleSessionMapper::toDTO);
}
@Override
public List<String[]> getDeletedTypeCount(String name, String type, Date startDate, Date endDate) {
return convertObjectListToStringList(saleSessionRepository.getDeletedTypeCount(type, name, startDate, endDate));
}
private List<String[]> convertObjectListToStringList(List<Object[]> objectList) {
if (objectList == null) {
return new ArrayList<>();
}
List<String[]> stringList = new ArrayList<>();
for (Object[] objectArray : objectList) {
if (objectArray != null && objectArray.length == 2) {
String[] stringArray = new String[2];
stringArray[0] = objectArray[0] != null ? String.valueOf(objectArray[0]) : "";
stringArray[1] = objectArray[1] != null ? String.valueOf(objectArray[1]) : "";
stringList.add(stringArray);
}
}
return stringList;
}
} }
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