diff --git a/src/main/java/kr/kro/photoliner/domain/photo/controller/PhotoController.java b/src/main/java/kr/kro/photoliner/domain/photo/controller/PhotoController.java index 8727e31..59f8c8c 100644 --- a/src/main/java/kr/kro/photoliner/domain/photo/controller/PhotoController.java +++ b/src/main/java/kr/kro/photoliner/domain/photo/controller/PhotoController.java @@ -40,9 +40,11 @@ public class PhotoController { @GetMapping public ResponseEntity getPhotos( @RequestParam Long userId, + @RequestParam(required = false) Boolean hasLocation, + @RequestParam(required = false) Boolean hasCapturedDate, @PageableDefault(sort = "capturedDt", direction = Sort.Direction.DESC) Pageable pageable ) { - return ResponseEntity.ok(photoService.getPhotosByIds(userId, pageable)); + return ResponseEntity.ok(photoService.getPhotosByIds(userId, hasLocation, hasCapturedDate, pageable)); } @GetMapping("/markers") diff --git a/src/main/java/kr/kro/photoliner/domain/photo/repository/PhotoRepository.java b/src/main/java/kr/kro/photoliner/domain/photo/repository/PhotoRepository.java index 7b82616..67a519d 100644 --- a/src/main/java/kr/kro/photoliner/domain/photo/repository/PhotoRepository.java +++ b/src/main/java/kr/kro/photoliner/domain/photo/repository/PhotoRepository.java @@ -12,8 +12,17 @@ public interface PhotoRepository extends JpaRepository { - Page findByUserId( + @Query(""" + select p + from Photo p + where p.userId = :userId + and (:hasLocation is null or (:hasLocation = true and p.location is not null) or (:hasLocation = false and p.location is null)) + and (:hasCapturedDate is null or (:hasCapturedDate = true and p.capturedDt is not null) or (:hasCapturedDate = false and p.capturedDt is null)) + """) + Page findByUserIdWithFilters( Long userId, + Boolean hasLocation, + Boolean hasCapturedDate, Pageable pageable ); diff --git a/src/main/java/kr/kro/photoliner/domain/photo/service/PhotoService.java b/src/main/java/kr/kro/photoliner/domain/photo/service/PhotoService.java index 9414be8..fbc520a 100644 --- a/src/main/java/kr/kro/photoliner/domain/photo/service/PhotoService.java +++ b/src/main/java/kr/kro/photoliner/domain/photo/service/PhotoService.java @@ -38,8 +38,9 @@ public class PhotoService { private static final String THUMBNAIL_BASE_PATH = "/images/thumb/"; @Transactional(readOnly = true) - public PhotosResponse getPhotosByIds(Long userId, Pageable pageable) { - return PhotosResponse.from(photoRepository.findByUserId(userId, pageable)); + public PhotosResponse getPhotosByIds(Long userId, Boolean hasLocation, Boolean hasCapturedDate, Pageable pageable) { + return PhotosResponse.from( + photoRepository.findByUserIdWithFilters(userId, hasLocation, hasCapturedDate, pageable)); } @Transactional(readOnly = true)