added filter by date for adoptions to backend
This commit is contained in:
@@ -17,6 +17,8 @@ import org.springframework.security.core.Authentication;
|
|||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/v1/adoptions")
|
@RequestMapping("/api/v1/adoptions")
|
||||||
public class AdoptionController {
|
public class AdoptionController {
|
||||||
@@ -36,6 +38,7 @@ public class AdoptionController {
|
|||||||
@RequestParam(required = false) Long customerId,
|
@RequestParam(required = false) Long customerId,
|
||||||
@RequestParam(required = false) String status,
|
@RequestParam(required = false) String status,
|
||||||
@RequestParam(required = false) Long storeId,
|
@RequestParam(required = false) Long storeId,
|
||||||
|
@RequestParam(required = false) String date,
|
||||||
Pageable pageable) {
|
Pageable pageable) {
|
||||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||||
String role = authentication.getAuthorities().stream()
|
String role = authentication.getAuthorities().stream()
|
||||||
@@ -49,7 +52,9 @@ public class AdoptionController {
|
|||||||
effectiveCustomerId = user.getId();
|
effectiveCustomerId = user.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
return ResponseEntity.ok(adoptionService.getAllAdoptions(q, effectiveCustomerId, status, storeId, pageable));
|
LocalDate adoptionDate = (date != null && !date.isBlank()) ? LocalDate.parse(date) : null;
|
||||||
|
|
||||||
|
return ResponseEntity.ok(adoptionService.getAllAdoptions(q, effectiveCustomerId, status, storeId, adoptionDate, pageable));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ 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.LocalDate;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
@@ -21,12 +22,14 @@ public interface AdoptionRepository extends JpaRepository<Adoption, Long> {
|
|||||||
")) AND " +
|
")) AND " +
|
||||||
"(:customerId IS NULL OR a.customer.id = :customerId) AND " +
|
"(:customerId IS NULL OR a.customer.id = :customerId) AND " +
|
||||||
"(:status IS NULL OR LOWER(a.adoptionStatus) = LOWER(:status)) AND " +
|
"(:status IS NULL OR LOWER(a.adoptionStatus) = LOWER(:status)) AND " +
|
||||||
"(:storeId IS NULL OR a.sourceStore.storeId = :storeId)")
|
"(:storeId IS NULL OR a.sourceStore.storeId = :storeId) AND " +
|
||||||
|
"(:date IS NULL OR a.adoptionDate = :date)")
|
||||||
Page<Adoption> searchAdoptions(
|
Page<Adoption> searchAdoptions(
|
||||||
@Param("q") String query,
|
@Param("q") String query,
|
||||||
@Param("customerId") Long customerId,
|
@Param("customerId") Long customerId,
|
||||||
@Param("status") String status,
|
@Param("status") String status,
|
||||||
@Param("storeId") Long storeId,
|
@Param("storeId") Long storeId,
|
||||||
|
@Param("date") LocalDate date,
|
||||||
Pageable pageable);
|
Pageable pageable);
|
||||||
|
|
||||||
Optional<Adoption> findFirstByPet_IdAndAdoptionStatusOrderByAdoptionDateDesc(Long petId, String adoptionStatus);
|
Optional<Adoption> findFirstByPet_IdAndAdoptionStatusOrderByAdoptionDateDesc(Long petId, String adoptionStatus);
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ import org.springframework.data.domain.Pageable;
|
|||||||
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.LocalDate;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class AdoptionService {
|
public class AdoptionService {
|
||||||
|
|
||||||
@@ -38,7 +40,7 @@ public class AdoptionService {
|
|||||||
this.storeRepository = storeRepository;
|
this.storeRepository = storeRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Page<AdoptionResponse> getAllAdoptions(String query, Long customerId, String status, Long storeId, Pageable pageable) {
|
public Page<AdoptionResponse> getAllAdoptions(String query, Long customerId, String status, Long storeId, LocalDate date, Pageable pageable) {
|
||||||
String normalizedQuery = normalizeFilter(query);
|
String normalizedQuery = normalizeFilter(query);
|
||||||
String normalizedStatus = normalizeFilter(status);
|
String normalizedStatus = normalizeFilter(status);
|
||||||
|
|
||||||
@@ -47,6 +49,7 @@ public class AdoptionService {
|
|||||||
customerId,
|
customerId,
|
||||||
normalizedStatus,
|
normalizedStatus,
|
||||||
storeId,
|
storeId,
|
||||||
|
date,
|
||||||
pageable
|
pageable
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user