Skip to content

Commit

Permalink
Merge pull request #16 from YAPP-Github/feature/#15
Browse files Browse the repository at this point in the history
feat: 사진 단건 조회 API 구현
  • Loading branch information
CChuYong authored Jul 7, 2024
2 parents 0f84480 + 7495c12 commit f574abd
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
13 changes: 12 additions & 1 deletion photo-service/src/main/java/kr/mafoo/photo/api/AlbumApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,24 @@
@Tag(name = "앨범 관련 API", description = "앨범 조회, 생성, 수정, 삭제 등 API")
@RequestMapping("/v1/albums")
public interface AlbumApi {
@Operation(summary = "앨범 조회", description = "앨범 목록을 조회합니다.")
@Operation(summary = "앨범 n건 조회", description = "앨범 목록을 조회합니다.")
@GetMapping
Flux<AlbumResponse> getAlbums(
@RequestMemberId
String memberId
);

@Operation(summary = "앨범 단건 조회", description = "앨범 단건을 조회합니다.")
@GetMapping("/{albumId}")
Mono<AlbumResponse> getAlbum(
@RequestMemberId
String memberId,

@Parameter(description = "앨범 ID", example = "test_album_id")
@PathVariable
String albumId
);

@Operation(summary = "앨범 생성", description = "앨범을 생성합니다.")
@PostMapping
Mono<AlbumResponse> createAlbum(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ public Flux<AlbumResponse> getAlbums(
.map(AlbumResponse::fromEntity);
}

@Override
public Mono<AlbumResponse> getAlbum(
String memberId,
String albumId
) {
return albumService
.findByAlbumId(albumId, memberId)
.map(AlbumResponse::fromEntity);
}

@Override
public Mono<AlbumResponse> createAlbum(
String memberId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ public Flux<AlbumEntity> findAllByOwnerMemberId(String ownerMemberId) {
return albumRepository.findAllByOwnerMemberId(ownerMemberId);
}

public Mono<AlbumEntity> findByAlbumId(String albumId, String requestMemberId) {
return albumRepository
.findById(albumId)
.switchIfEmpty(Mono.error(new AlbumNotFoundException()))
.flatMap(albumEntity -> {
if(!albumEntity.getOwnerMemberId().equals(requestMemberId)) {
// 내 앨범이 아니면 그냥 없는 앨범 처리
return Mono.error(new AlbumNotFoundException());
} else {
return Mono.just(albumEntity);
}
});
}

public Mono<Void> deleteAlbumById(String albumId, String requestMemberId) {
return albumRepository
.findById(albumId)
Expand Down

0 comments on commit f574abd

Please sign in to comment.