Skip to content

Commit

Permalink
Merge pull request #66 from YAPP-Github/feature/MAFOO-122
Browse files Browse the repository at this point in the history
[MAFOO-122] feat: ์‚ฌ์ง„ ์กฐํšŒ API์— ์ •๋ ฌ ์˜ต์…˜์„ ์ถ”๊ฐ€ํ–ˆ์–ด์š”
  • Loading branch information
gmkim20713 authored Oct 17, 2024
2 parents 959c7d4 + c4c354b commit e74511c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
6 changes: 5 additions & 1 deletion photo-service/src/main/java/kr/mafoo/photo/api/PhotoApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ Flux<PhotoResponse> getPhotos(
@ULID
@Parameter(description = "์•จ๋ฒ” ID", example = "test_album_id")
@RequestParam
String albumId
String albumId,

@Parameter(description = "์ •๋ ฌ ์ข…๋ฅ˜", example = "ASC | DESC")
@RequestParam(required = false)
String sort
);

@Operation(summary = "์‚ฌ์ง„ ์ƒ์„ฑ", description = "์‚ฌ์ง„์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ public class PhotoController implements PhotoApi {
@Override
public Flux<PhotoResponse> getPhotos(
String memberId,
String albumId
String albumId,
String sort
){
return photoService
.findAllByAlbumId(albumId, memberId)
.findAllByAlbumId(albumId, memberId, sort)
.map(PhotoResponse::fromEntity);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
public interface PhotoRepository extends R2dbcRepository<PhotoEntity, String> {
Flux<PhotoEntity> findAllByAlbumIdOrderByDisplayIndexDesc(String ownerAlbumId);

Flux<PhotoEntity> findAllByAlbumIdOrderByCreatedAtDesc(String ownerAlbumId);

Flux<PhotoEntity> findAllByAlbumIdOrderByCreatedAtAsc(String ownerAlbumId);

@Modifying
@Query("UPDATE photo SET display_index = display_index - 1 WHERE album_id = :albumId AND display_index > :startIndex")
Mono<Void> popDisplayIndexGreaterThan(String albumId, int startIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public Flux<PhotoEntity> uploadPhoto(Flux<FilePart> files, String requestMemberI
).sequential();
}

public Flux<PhotoEntity> findAllByAlbumId(String albumId, String requestMemberId) {
public Flux<PhotoEntity> findAllByAlbumId(String albumId, String requestMemberId, String sort) {
return albumRepository
.findById(albumId)
.switchIfEmpty(Mono.error(new AlbumNotFoundException()))
Expand All @@ -79,7 +79,13 @@ public Flux<PhotoEntity> findAllByAlbumId(String albumId, String requestMemberId
// ๋‚ด ์•จ๋ฒ”์ด ์•„๋‹ˆ๋ฉด ๊ทธ๋ƒฅ ์—†๋Š” ์•จ๋ฒ” ์ฒ˜๋ฆฌ
return Mono.error(new AlbumNotFoundException());
} else {
return photoRepository.findAllByAlbumIdOrderByDisplayIndexDesc(albumId);
String sortMethod = (sort == null) ? "CUSTOM" : sort.toUpperCase();

return switch (sortMethod) {
case "ASC" -> photoRepository.findAllByAlbumIdOrderByCreatedAtAsc(albumId);
case "DESC" -> photoRepository.findAllByAlbumIdOrderByCreatedAtDesc(albumId);
default -> photoRepository.findAllByAlbumIdOrderByDisplayIndexDesc(albumId);
};
}
});
}
Expand Down

0 comments on commit e74511c

Please sign in to comment.