Skip to content

Commit bde9ef4

Browse files
authored
feat: 사진 필터링 기능 추가 (#55)
1 parent ecb4a08 commit bde9ef4

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

src/main/java/kr/kro/photoliner/domain/photo/controller/PhotoController.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ public class PhotoController {
4040
@GetMapping
4141
public ResponseEntity<PhotosResponse> getPhotos(
4242
@RequestParam Long userId,
43+
@RequestParam(required = false) Boolean hasLocation,
44+
@RequestParam(required = false) Boolean hasCapturedDate,
4345
@PageableDefault(sort = "capturedDt", direction = Sort.Direction.DESC) Pageable pageable
4446
) {
45-
return ResponseEntity.ok(photoService.getPhotosByIds(userId, pageable));
47+
return ResponseEntity.ok(photoService.getPhotosByIds(userId, hasLocation, hasCapturedDate, pageable));
4648
}
4749

4850
@GetMapping("/markers")

src/main/java/kr/kro/photoliner/domain/photo/repository/PhotoRepository.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,17 @@
1212

1313
public interface PhotoRepository extends JpaRepository<Photo, Long> {
1414

15-
Page<Photo> findByUserId(
15+
@Query("""
16+
select p
17+
from Photo p
18+
where p.userId = :userId
19+
and (:hasLocation is null or (:hasLocation = true and p.location is not null) or (:hasLocation = false and p.location is null))
20+
and (:hasCapturedDate is null or (:hasCapturedDate = true and p.capturedDt is not null) or (:hasCapturedDate = false and p.capturedDt is null))
21+
""")
22+
Page<Photo> findByUserIdWithFilters(
1623
Long userId,
24+
Boolean hasLocation,
25+
Boolean hasCapturedDate,
1726
Pageable pageable
1827
);
1928

src/main/java/kr/kro/photoliner/domain/photo/service/PhotoService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ public class PhotoService {
3838
private static final String THUMBNAIL_BASE_PATH = "/images/thumb/";
3939

4040
@Transactional(readOnly = true)
41-
public PhotosResponse getPhotosByIds(Long userId, Pageable pageable) {
42-
return PhotosResponse.from(photoRepository.findByUserId(userId, pageable));
41+
public PhotosResponse getPhotosByIds(Long userId, Boolean hasLocation, Boolean hasCapturedDate, Pageable pageable) {
42+
return PhotosResponse.from(
43+
photoRepository.findByUserIdWithFilters(userId, hasLocation, hasCapturedDate, pageable));
4344
}
4445

4546
@Transactional(readOnly = true)

0 commit comments

Comments
 (0)