diff --git a/backend/src/main/java/com/petshop/backend/controller/AdoptionController.java b/backend/src/main/java/com/petshop/backend/controller/AdoptionController.java index a8795b87..23e372bf 100644 --- a/backend/src/main/java/com/petshop/backend/controller/AdoptionController.java +++ b/backend/src/main/java/com/petshop/backend/controller/AdoptionController.java @@ -17,6 +17,8 @@ import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.web.bind.annotation.*; +import java.time.LocalDate; + @RestController @RequestMapping("/api/v1/adoptions") public class AdoptionController { @@ -36,6 +38,7 @@ public class AdoptionController { @RequestParam(required = false) Long customerId, @RequestParam(required = false) String status, @RequestParam(required = false) Long storeId, + @RequestParam(required = false) String date, Pageable pageable) { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); String role = authentication.getAuthorities().stream() @@ -49,7 +52,9 @@ public class AdoptionController { 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}") diff --git a/backend/src/main/java/com/petshop/backend/repository/AdoptionRepository.java b/backend/src/main/java/com/petshop/backend/repository/AdoptionRepository.java index 2c93c7c7..f4594a26 100644 --- a/backend/src/main/java/com/petshop/backend/repository/AdoptionRepository.java +++ b/backend/src/main/java/com/petshop/backend/repository/AdoptionRepository.java @@ -8,6 +8,7 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import java.time.LocalDate; import java.util.Optional; @Repository @@ -21,12 +22,14 @@ public interface AdoptionRepository extends JpaRepository { ")) AND " + "(:customerId IS NULL OR a.customer.id = :customerId) 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 searchAdoptions( @Param("q") String query, @Param("customerId") Long customerId, @Param("status") String status, @Param("storeId") Long storeId, + @Param("date") LocalDate date, Pageable pageable); Optional findFirstByPet_IdAndAdoptionStatusOrderByAdoptionDateDesc(Long petId, String adoptionStatus); diff --git a/backend/src/main/java/com/petshop/backend/service/AdoptionService.java b/backend/src/main/java/com/petshop/backend/service/AdoptionService.java index 08121355..ab528b79 100644 --- a/backend/src/main/java/com/petshop/backend/service/AdoptionService.java +++ b/backend/src/main/java/com/petshop/backend/service/AdoptionService.java @@ -17,6 +17,8 @@ import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDate; + @Service public class AdoptionService { @@ -38,7 +40,7 @@ public class AdoptionService { this.storeRepository = storeRepository; } - public Page getAllAdoptions(String query, Long customerId, String status, Long storeId, Pageable pageable) { + public Page getAllAdoptions(String query, Long customerId, String status, Long storeId, LocalDate date, Pageable pageable) { String normalizedQuery = normalizeFilter(query); String normalizedStatus = normalizeFilter(status); @@ -47,6 +49,7 @@ public class AdoptionService { customerId, normalizedStatus, storeId, + date, pageable );