WIP: Update morefiles #152
@@ -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}")
|
||||
|
||||
@@ -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<Adoption, Long> {
|
||||
")) 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<Adoption> searchAdoptions(
|
||||
@Param("q") String query,
|
||||
@Param("customerId") Long customerId,
|
||||
@Param("status") String status,
|
||||
@Param("storeId") Long storeId,
|
||||
@Param("date") LocalDate date,
|
||||
Pageable pageable);
|
||||
|
||||
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.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Service
|
||||
public class AdoptionService {
|
||||
|
||||
@@ -38,7 +40,7 @@ public class AdoptionService {
|
||||
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 normalizedStatus = normalizeFilter(status);
|
||||
|
||||
@@ -47,6 +49,7 @@ public class AdoptionService {
|
||||
customerId,
|
||||
normalizedStatus,
|
||||
storeId,
|
||||
date,
|
||||
pageable
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user