Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ public class PhotoController {
@GetMapping
public ResponseEntity<PhotosResponse> 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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,17 @@

public interface PhotoRepository extends JpaRepository<Photo, Long> {

Page<Photo> 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<Photo> findByUserIdWithFilters(
Long userId,
Boolean hasLocation,
Boolean hasCapturedDate,
Pageable pageable
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading