Skip to content
Extraits de code Groupes Projets
Valider ca9c81d2 rédigé par Mohamed Lemine BAILLAHI's avatar Mohamed Lemine BAILLAHI
Parcourir les fichiers

Merge branch 'feature/MYD-628' into 'develop'

MYD-628/add pagination, sort and search for sale ssesion

Closes MYD-628

See merge request !112
parents 4da3fe9e f43dd49a
Branches
1 requête de fusion!112MYD-628/add pagination, sort and search for sale ssesion
Pipeline #11922 en échec avec les étapes
in 26 secondes
## [1.0.71-RELEASE]
### Added
- New features that have been added.
- MYD-628/add pagination, sort and search for sale ssesion
### Changed
- Changes in existing functionality.
......
......@@ -27,4 +27,6 @@ public class Paths {
public static final String ADD_TO_CART_TRENDS = "/add-to-cart-trends";
public static final String CART_COUNT = "/cart-count";
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";
}
package com.marketingconfort.mydressin.controllers;
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.SessionOrderDTO;
import com.marketingconfort.mydressin.dtos.ItemRequestDTO;
......@@ -9,12 +10,15 @@ import com.marketingconfort.mydressin.exceptions.SaleSessionExpiredException;
import com.marketingconfort.mydressin.exceptions.SaleSessionNotFoundException;
import com.marketingconfort.mydressin.services.SaleSessionService;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
......@@ -22,7 +26,6 @@ import java.util.concurrent.CompletableFuture;
@RestController
@RequestMapping(value = "/api/cart", method = RequestMethod.OPTIONS)
@AllArgsConstructor
public class SaleSessionController {
private final SaleSessionService saleSessionService;
......@@ -138,5 +141,33 @@ public class SaleSessionController {
SaleSessionDTO updatedSession = saleSessionService.restockSaleSession(sessionId);
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);
}
}
......@@ -2,11 +2,14 @@ package com.marketingconfort.mydressin.repositories;
import com.marketingconfort.mydressin.common.cart.enumurations.ItemCartStatus;
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.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.Date;
import java.util.List;
@Repository
......@@ -68,4 +71,26 @@ public interface SaleSessionRepository extends JpaRepository<SaleSession, Long>
"JOIN so.itemCart ic " +
"WHERE ss.id = :sessionId")
Long getTotalPaidProducts(@Param("sessionId") Long sessionId);
@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);
}
......@@ -6,10 +6,12 @@ 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 org.springframework.data.domain.Page;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.concurrent.CompletableFuture;
......@@ -29,4 +31,7 @@ public interface SaleSessionService {
SaleSessionDTO updateSaleSessionDetails(Long sessionId, String newName, String newDescription);
boolean deleteSaleSessionById(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);
}
......@@ -19,16 +19,17 @@ import com.marketingconfort.mydressin.repositories.SaleSessionRepository;
import com.marketingconfort.mydressin.repositories.SessionOrderRepository;
import com.marketingconfort.mydressin.services.*;
import lombok.AllArgsConstructor;
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.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
......@@ -244,4 +245,42 @@ public class SaleSessionServiceImp implements SaleSessionService {
SaleSession updatedSaleSession = saleSessionRepository.save(saleSession);
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));
}
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