diff --git a/CHANGELOG.md b/CHANGELOG.md index 168c4dea3982d44d0579c17180108d229dadf972..97721a4c2d126c972a23a84ab18128d22739c669 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,25 @@ +## [1.0.72-RELEASE] +### 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 ssesion +- MYD-628/add pagination, sort and search for sale session ### Changed - Changes in existing functionality. diff --git a/src/main/java/com/marketingconfort/mydressin/constants/Paths.java b/src/main/java/com/marketingconfort/mydressin/constants/Paths.java index 503aacd584365a56bcad191418fb794cb4b9d533..e156a0a192511991cf0085b8e8408828293570ae 100644 --- a/src/main/java/com/marketingconfort/mydressin/constants/Paths.java +++ b/src/main/java/com/marketingconfort/mydressin/constants/Paths.java @@ -29,4 +29,6 @@ public class Paths { 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"; } diff --git a/src/main/java/com/marketingconfort/mydressin/controllers/SaleSessionController.java b/src/main/java/com/marketingconfort/mydressin/controllers/SaleSessionController.java index 6d60f5bc015fdb102072b73362d1a37d009123c6..45b124d4ffee364c1484c51f39d729b43327679c 100644 --- a/src/main/java/com/marketingconfort/mydressin/controllers/SaleSessionController.java +++ b/src/main/java/com/marketingconfort/mydressin/controllers/SaleSessionController.java @@ -169,5 +169,33 @@ public class SaleSessionController { 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); + } + } diff --git a/src/main/java/com/marketingconfort/mydressin/repositories/SaleSessionRepository.java b/src/main/java/com/marketingconfort/mydressin/repositories/SaleSessionRepository.java index 84317f3a1d3ae691a00bdabc0a97a19712e27918..1b10344c612b2e353cfebe5c3fa01570fddee3e7 100644 --- a/src/main/java/com/marketingconfort/mydressin/repositories/SaleSessionRepository.java +++ b/src/main/java/com/marketingconfort/mydressin/repositories/SaleSessionRepository.java @@ -93,4 +93,28 @@ public interface SaleSessionRepository extends JpaRepository<SaleSession, Long> @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); } diff --git a/src/main/java/com/marketingconfort/mydressin/services/SaleSessionService.java b/src/main/java/com/marketingconfort/mydressin/services/SaleSessionService.java index 3f86b8917530ef170519cd131738b650d87f4256..7d93f429adaf9bac6493858fc58fa45df4c19a9f 100644 --- a/src/main/java/com/marketingconfort/mydressin/services/SaleSessionService.java +++ b/src/main/java/com/marketingconfort/mydressin/services/SaleSessionService.java @@ -34,4 +34,8 @@ public interface SaleSessionService { 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); } 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 86e8f0840a5007c9874f14785ee8f4df661e2aed..abb4cab3bd1377d8328de2402318211347fbe083 100644 --- a/src/main/java/com/marketingconfort/mydressin/services/impl/SaleSessionServiceImp.java +++ b/src/main/java/com/marketingconfort/mydressin/services/impl/SaleSessionServiceImp.java @@ -262,6 +262,23 @@ public class SaleSessionServiceImp implements SaleSessionService { 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<>();