From 72a15e6974669f1f254130b27b530ea62c184a19 Mon Sep 17 00:00:00 2001 From: Gyoungmin Kim Date: Sat, 17 Aug 2024 14:05:53 +0900 Subject: [PATCH 1/5] feature: implement update photo list's album api --- .../main/java/kr/mafoo/photo/api/PhotoApi.java | 14 +++++++++++++- .../mafoo/photo/controller/PhotoController.java | 16 +++++++++++++++- .../request/PhotoListUpdateAlbumIdRequest.java | 16 ++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 photo-service/src/main/java/kr/mafoo/photo/controller/dto/request/PhotoListUpdateAlbumIdRequest.java diff --git a/photo-service/src/main/java/kr/mafoo/photo/api/PhotoApi.java b/photo-service/src/main/java/kr/mafoo/photo/api/PhotoApi.java index 4bb1b21..98481a4 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/api/PhotoApi.java +++ b/photo-service/src/main/java/kr/mafoo/photo/api/PhotoApi.java @@ -7,6 +7,7 @@ import kr.mafoo.photo.annotation.RequestMemberId; import kr.mafoo.photo.annotation.ULID; import kr.mafoo.photo.controller.dto.request.PhotoCreateRequest; +import kr.mafoo.photo.controller.dto.request.PhotoListUpdateAlbumIdRequest; import kr.mafoo.photo.controller.dto.request.PhotoUpdateAlbumIdRequest; import kr.mafoo.photo.controller.dto.response.PhotoResponse; import org.springframework.validation.annotation.Validated; @@ -41,7 +42,7 @@ Mono createPhoto( PhotoCreateRequest request ); - @Operation(summary = "사진 앨범 수정", description = "사진을 다른 앨범으로 이동시킵니다.") + @Operation(summary = "사진 앨범 단건 수정", description = "사진 한 개를 다른 앨범으로 이동시킵니다.") @PatchMapping("/{photoId}/album") Mono updatePhotoAlbum( @RequestMemberId @@ -57,6 +58,17 @@ Mono updatePhotoAlbum( PhotoUpdateAlbumIdRequest request ); + @Operation(summary = "사진 앨범 n건 수정", description = "사진 여러 개를 다른 앨범으로 이동시킵니다.") + @PatchMapping("/album") + Flux updatePhotoListAlbum( + @RequestMemberId + String memberId, + + @Valid + @RequestBody + PhotoListUpdateAlbumIdRequest request + ); + @Operation(summary = "사진 삭제", description = "사진을 삭제합니다.") @DeleteMapping("{photoId}") Mono deletePhoto( diff --git a/photo-service/src/main/java/kr/mafoo/photo/controller/PhotoController.java b/photo-service/src/main/java/kr/mafoo/photo/controller/PhotoController.java index a4f0efe..0ea9f0f 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/controller/PhotoController.java +++ b/photo-service/src/main/java/kr/mafoo/photo/controller/PhotoController.java @@ -2,6 +2,7 @@ import kr.mafoo.photo.api.PhotoApi; import kr.mafoo.photo.controller.dto.request.PhotoCreateRequest; +import kr.mafoo.photo.controller.dto.request.PhotoListUpdateAlbumIdRequest; import kr.mafoo.photo.controller.dto.request.PhotoUpdateAlbumIdRequest; import kr.mafoo.photo.controller.dto.response.PhotoResponse; import kr.mafoo.photo.service.PhotoService; @@ -10,7 +11,6 @@ import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -import static kr.mafoo.photo.domain.BrandType.LIFE_FOUR_CUTS; @RequiredArgsConstructor @RestController @@ -49,6 +49,20 @@ public Mono updatePhotoAlbum( .map(PhotoResponse::fromEntity); } + @Override + public Flux updatePhotoListAlbum( + String memberId, + PhotoListUpdateAlbumIdRequest request + ){ + return Flux.fromArray(request.photoIdList()) + .flatMap(photoId -> + photoService + .updatePhotoAlbumId(photoId, request.albumId(), memberId) + .map(PhotoResponse::fromEntity) + ); + } + + @Override public Mono deletePhoto( String memberId, diff --git a/photo-service/src/main/java/kr/mafoo/photo/controller/dto/request/PhotoListUpdateAlbumIdRequest.java b/photo-service/src/main/java/kr/mafoo/photo/controller/dto/request/PhotoListUpdateAlbumIdRequest.java new file mode 100644 index 0000000..7cce774 --- /dev/null +++ b/photo-service/src/main/java/kr/mafoo/photo/controller/dto/request/PhotoListUpdateAlbumIdRequest.java @@ -0,0 +1,16 @@ +package kr.mafoo.photo.controller.dto.request; + +import io.swagger.v3.oas.annotations.media.Schema; +import kr.mafoo.photo.annotation.ULID; + +@Schema(description = "사진 앨범 수정 요청") +public record PhotoListUpdateAlbumIdRequest( + + @Schema(description = "사진 ID 목록") + String[] photoIdList, + + @ULID + @Schema(description = "앨범 ID", example = "test_album_id") + String albumId +) { +} From 74f528fd3f43420c808f6f32aa850ffd6c2c419f Mon Sep 17 00:00:00 2001 From: Gyoungmin Kim Date: Sat, 17 Aug 2024 14:51:16 +0900 Subject: [PATCH 2/5] refactor: create updatePhotoListAlbumId in photo service --- .../photo/controller/PhotoController.java | 9 ++--- .../kr/mafoo/photo/service/PhotoService.java | 36 +++++++++++-------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/photo-service/src/main/java/kr/mafoo/photo/controller/PhotoController.java b/photo-service/src/main/java/kr/mafoo/photo/controller/PhotoController.java index 0ea9f0f..5daf9f4 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/controller/PhotoController.java +++ b/photo-service/src/main/java/kr/mafoo/photo/controller/PhotoController.java @@ -54,12 +54,9 @@ public Flux updatePhotoListAlbum( String memberId, PhotoListUpdateAlbumIdRequest request ){ - return Flux.fromArray(request.photoIdList()) - .flatMap(photoId -> - photoService - .updatePhotoAlbumId(photoId, request.albumId(), memberId) - .map(PhotoResponse::fromEntity) - ); + return photoService + .updatePhotoListAlbumId(request.photoIdList(), request.albumId(), memberId) + .map(PhotoResponse::fromEntity); } diff --git a/photo-service/src/main/java/kr/mafoo/photo/service/PhotoService.java b/photo-service/src/main/java/kr/mafoo/photo/service/PhotoService.java index bc33cf6..08d6ad0 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/service/PhotoService.java +++ b/photo-service/src/main/java/kr/mafoo/photo/service/PhotoService.java @@ -66,6 +66,14 @@ public Mono deletePhotoById(String photoId, String requestMemberId) { }); } + @Transactional + public Flux updatePhotoListAlbumId(String[] photoIds, String albumId, String requestMemberId) { + return Flux.fromArray(photoIds) + .flatMap(photoId -> + this.updatePhotoAlbumId(photoId, albumId, requestMemberId) + ); + } + @Transactional public Mono updatePhotoAlbumId(String photoId, String albumId, String requestMemberId) { return photoRepository @@ -80,21 +88,21 @@ public Mono updatePhotoAlbumId(String photoId, String albumId, Stri if (!photoEntity.getOwnerMemberId().equals(requestMemberId)) { // 내 사진이 아니면 그냥 없는 사진 처리 return Mono.error(new PhotoNotFoundException()); - } else { - return albumRepository - .findById(albumId) - .switchIfEmpty(Mono.error(new AlbumNotFoundException())) - .flatMap(albumEntity -> { - if (!albumEntity.getOwnerMemberId().equals(requestMemberId)) { - // 내 앨범이 아니면 그냥 없는 앨범 처리 - return Mono.error(new AlbumNotFoundException()); - } else { - return albumService.decreaseAlbumPhotoCount(photoEntity.getAlbumId(), requestMemberId) - .then(albumService.increaseAlbumPhotoCount(albumId, requestMemberId)) - .then(photoRepository.save(photoEntity.updateAlbumId(albumId))); - } - }); } + + return albumRepository + .findById(albumId) + .switchIfEmpty(Mono.error(new AlbumNotFoundException())) + .flatMap(albumEntity -> { + if (!albumEntity.getOwnerMemberId().equals(requestMemberId)) { + // 내 앨범이 아니면 그냥 없는 앨범 처리 + return Mono.error(new AlbumNotFoundException()); + } + + return albumService.decreaseAlbumPhotoCount(photoEntity.getAlbumId(), requestMemberId) + .then(albumService.increaseAlbumPhotoCount(albumId, requestMemberId)) + .then(photoRepository.save(photoEntity.updateAlbumId(albumId))); + }); }); } From 23f1b572710c103db79d60b83cca3574854df731 Mon Sep 17 00:00:00 2001 From: Gyoungmin Kim Date: Sun, 18 Aug 2024 13:02:28 +0900 Subject: [PATCH 3/5] refactor: change dto column name --- .../controller/dto/request/PhotoListUpdateAlbumIdRequest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/photo-service/src/main/java/kr/mafoo/photo/controller/dto/request/PhotoListUpdateAlbumIdRequest.java b/photo-service/src/main/java/kr/mafoo/photo/controller/dto/request/PhotoListUpdateAlbumIdRequest.java index 7cce774..5400be0 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/controller/dto/request/PhotoListUpdateAlbumIdRequest.java +++ b/photo-service/src/main/java/kr/mafoo/photo/controller/dto/request/PhotoListUpdateAlbumIdRequest.java @@ -7,7 +7,7 @@ public record PhotoListUpdateAlbumIdRequest( @Schema(description = "사진 ID 목록") - String[] photoIdList, + String[] photoIds, @ULID @Schema(description = "앨범 ID", example = "test_album_id") From dc7a9f03712d340ea171a4da6785526b544e631d Mon Sep 17 00:00:00 2001 From: Gyoungmin Kim Date: Mon, 19 Aug 2024 23:14:01 +0900 Subject: [PATCH 4/5] refactor: clarify naming of updatePhotoListAlbum api as updatePhotoBulkAlbum api --- .../src/main/java/kr/mafoo/photo/api/PhotoApi.java | 8 ++++---- .../java/kr/mafoo/photo/controller/PhotoController.java | 8 ++++---- ...mIdRequest.java => PhotoBulkUpdateAlbumIdRequest.java} | 2 +- .../main/java/kr/mafoo/photo/service/PhotoService.java | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) rename photo-service/src/main/java/kr/mafoo/photo/controller/dto/request/{PhotoListUpdateAlbumIdRequest.java => PhotoBulkUpdateAlbumIdRequest.java} (89%) diff --git a/photo-service/src/main/java/kr/mafoo/photo/api/PhotoApi.java b/photo-service/src/main/java/kr/mafoo/photo/api/PhotoApi.java index 98481a4..e59f2ee 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/api/PhotoApi.java +++ b/photo-service/src/main/java/kr/mafoo/photo/api/PhotoApi.java @@ -7,7 +7,7 @@ import kr.mafoo.photo.annotation.RequestMemberId; import kr.mafoo.photo.annotation.ULID; import kr.mafoo.photo.controller.dto.request.PhotoCreateRequest; -import kr.mafoo.photo.controller.dto.request.PhotoListUpdateAlbumIdRequest; +import kr.mafoo.photo.controller.dto.request.PhotoBulkUpdateAlbumIdRequest; import kr.mafoo.photo.controller.dto.request.PhotoUpdateAlbumIdRequest; import kr.mafoo.photo.controller.dto.response.PhotoResponse; import org.springframework.validation.annotation.Validated; @@ -59,14 +59,14 @@ Mono updatePhotoAlbum( ); @Operation(summary = "사진 앨범 n건 수정", description = "사진 여러 개를 다른 앨범으로 이동시킵니다.") - @PatchMapping("/album") - Flux updatePhotoListAlbum( + @PatchMapping("/bulk/album") + Flux updatePhotoBulkAlbum( @RequestMemberId String memberId, @Valid @RequestBody - PhotoListUpdateAlbumIdRequest request + PhotoBulkUpdateAlbumIdRequest request ); @Operation(summary = "사진 삭제", description = "사진을 삭제합니다.") diff --git a/photo-service/src/main/java/kr/mafoo/photo/controller/PhotoController.java b/photo-service/src/main/java/kr/mafoo/photo/controller/PhotoController.java index 5daf9f4..7edbd7b 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/controller/PhotoController.java +++ b/photo-service/src/main/java/kr/mafoo/photo/controller/PhotoController.java @@ -2,7 +2,7 @@ import kr.mafoo.photo.api.PhotoApi; import kr.mafoo.photo.controller.dto.request.PhotoCreateRequest; -import kr.mafoo.photo.controller.dto.request.PhotoListUpdateAlbumIdRequest; +import kr.mafoo.photo.controller.dto.request.PhotoBulkUpdateAlbumIdRequest; import kr.mafoo.photo.controller.dto.request.PhotoUpdateAlbumIdRequest; import kr.mafoo.photo.controller.dto.response.PhotoResponse; import kr.mafoo.photo.service.PhotoService; @@ -50,12 +50,12 @@ public Mono updatePhotoAlbum( } @Override - public Flux updatePhotoListAlbum( + public Flux updatePhotoBulkAlbum( String memberId, - PhotoListUpdateAlbumIdRequest request + PhotoBulkUpdateAlbumIdRequest request ){ return photoService - .updatePhotoListAlbumId(request.photoIdList(), request.albumId(), memberId) + .updatePhotoBulkAlbumId(request.photoIds(), request.albumId(), memberId) .map(PhotoResponse::fromEntity); } diff --git a/photo-service/src/main/java/kr/mafoo/photo/controller/dto/request/PhotoListUpdateAlbumIdRequest.java b/photo-service/src/main/java/kr/mafoo/photo/controller/dto/request/PhotoBulkUpdateAlbumIdRequest.java similarity index 89% rename from photo-service/src/main/java/kr/mafoo/photo/controller/dto/request/PhotoListUpdateAlbumIdRequest.java rename to photo-service/src/main/java/kr/mafoo/photo/controller/dto/request/PhotoBulkUpdateAlbumIdRequest.java index 5400be0..ff3e67d 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/controller/dto/request/PhotoListUpdateAlbumIdRequest.java +++ b/photo-service/src/main/java/kr/mafoo/photo/controller/dto/request/PhotoBulkUpdateAlbumIdRequest.java @@ -4,7 +4,7 @@ import kr.mafoo.photo.annotation.ULID; @Schema(description = "사진 앨범 수정 요청") -public record PhotoListUpdateAlbumIdRequest( +public record PhotoBulkUpdateAlbumIdRequest( @Schema(description = "사진 ID 목록") String[] photoIds, diff --git a/photo-service/src/main/java/kr/mafoo/photo/service/PhotoService.java b/photo-service/src/main/java/kr/mafoo/photo/service/PhotoService.java index 08d6ad0..e6c0ca8 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/service/PhotoService.java +++ b/photo-service/src/main/java/kr/mafoo/photo/service/PhotoService.java @@ -67,7 +67,7 @@ public Mono deletePhotoById(String photoId, String requestMemberId) { } @Transactional - public Flux updatePhotoListAlbumId(String[] photoIds, String albumId, String requestMemberId) { + public Flux updatePhotoBulkAlbumId(String[] photoIds, String albumId, String requestMemberId) { return Flux.fromArray(photoIds) .flatMap(photoId -> this.updatePhotoAlbumId(photoId, albumId, requestMemberId) From c168764886c0f1e974c74fad81aa71c51beb368d Mon Sep 17 00:00:00 2001 From: Gyoungmin Kim Date: Mon, 19 Aug 2024 23:20:00 +0900 Subject: [PATCH 5/5] refactor: add schema example for PhotoBulkUpdateAlbumIdRequest --- .../dto/request/PhotoBulkUpdateAlbumIdRequest.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/photo-service/src/main/java/kr/mafoo/photo/controller/dto/request/PhotoBulkUpdateAlbumIdRequest.java b/photo-service/src/main/java/kr/mafoo/photo/controller/dto/request/PhotoBulkUpdateAlbumIdRequest.java index ff3e67d..258c37c 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/controller/dto/request/PhotoBulkUpdateAlbumIdRequest.java +++ b/photo-service/src/main/java/kr/mafoo/photo/controller/dto/request/PhotoBulkUpdateAlbumIdRequest.java @@ -1,12 +1,16 @@ package kr.mafoo.photo.controller.dto.request; +import io.swagger.v3.oas.annotations.media.ArraySchema; import io.swagger.v3.oas.annotations.media.Schema; import kr.mafoo.photo.annotation.ULID; @Schema(description = "사진 앨범 수정 요청") public record PhotoBulkUpdateAlbumIdRequest( - @Schema(description = "사진 ID 목록") + @ArraySchema( + schema = @Schema(description = "사진 ID 목록"), + arraySchema = @Schema(example = "[\"test_photo_id_1\", \"test_photo_id_2\", \"test_photo_id_3\"]") + ) String[] photoIds, @ULID