From 4b20ec0b0926f1d510c201f5fb8defadfa059578 Mon Sep 17 00:00:00 2001 From: Gyoungmin Kim Date: Sat, 27 Jul 2024 12:14:46 +0900 Subject: [PATCH 1/4] feat : create updateOwnerMemberId for photo entity --- .../src/main/java/kr/mafoo/photo/domain/PhotoEntity.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/photo-service/src/main/java/kr/mafoo/photo/domain/PhotoEntity.java b/photo-service/src/main/java/kr/mafoo/photo/domain/PhotoEntity.java index 35db5ef..dd908ce 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/domain/PhotoEntity.java +++ b/photo-service/src/main/java/kr/mafoo/photo/domain/PhotoEntity.java @@ -62,6 +62,11 @@ public String getId() { return photoId; } + public PhotoEntity updateOwnerMemberId(String ownerMemberId) { + this.ownerMemberId = ownerMemberId; + return this; + } + public PhotoEntity updateAlbumId(String albumId) { this.albumId = albumId; return this; From a222963f3802af954ab7e3ad26a60aeac155f273 Mon Sep 17 00:00:00 2001 From: Gyoungmin Kim Date: Sat, 27 Jul 2024 12:15:36 +0900 Subject: [PATCH 2/4] feat : add photo entity ownerMemberId checkout and setting logic if null --- .../java/kr/mafoo/photo/service/PhotoService.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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 39fcdb0..be3d734 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 @@ -37,7 +37,7 @@ public Flux findAllByAlbumId(String albumId, String requestMemberId .findById(albumId) .switchIfEmpty(Mono.error(new AlbumNotFoundException())) .flatMapMany(albumEntity -> { - if(!albumEntity.getOwnerMemberId().equals(requestMemberId)) { + if (!albumEntity.getOwnerMemberId().equals(requestMemberId)) { // 내 앨범이 아니면 그냥 없는 앨범 처리 return Mono.error(new AlbumNotFoundException()); } else { @@ -51,7 +51,7 @@ public Mono deletePhotoById(String photoId, String requestMemberId) { .findById(photoId) .switchIfEmpty(Mono.error(new PhotoNotFoundException())) .flatMap(photoEntity -> { - if(!photoEntity.getOwnerMemberId().equals(requestMemberId)) { + if (!photoEntity.getOwnerMemberId().equals(requestMemberId)) { // 내 사진이 아니면 그냥 없는 사진 처리 return Mono.error(new PhotoNotFoundException()); } else { @@ -66,7 +66,11 @@ public Mono updatePhotoAlbumId(String photoId, String albumId, Stri .findById(photoId) .switchIfEmpty(Mono.error(new PhotoNotFoundException())) .flatMap(photoEntity -> { - if(!photoEntity.getOwnerMemberId().equals(requestMemberId)) { + if (photoEntity.getOwnerMemberId() == null) { + photoRepository.save(photoEntity.updateOwnerMemberId(requestMemberId)); + } + + if (!photoEntity.getOwnerMemberId().equals(requestMemberId)) { // 내 사진이 아니면 그냥 없는 사진 처리 return Mono.error(new PhotoNotFoundException()); } else { @@ -74,7 +78,7 @@ public Mono updatePhotoAlbumId(String photoId, String albumId, Stri .findById(albumId) .switchIfEmpty(Mono.error(new AlbumNotFoundException())) .flatMap(albumEntity -> { - if(!albumEntity.getOwnerMemberId().equals(requestMemberId)) { + if (!albumEntity.getOwnerMemberId().equals(requestMemberId)) { // 내 앨범이 아니면 그냥 없는 앨범 처리 return Mono.error(new AlbumNotFoundException()); } else { From b54b3f4c86ddfea9f209770397b3cf08623a31a1 Mon Sep 17 00:00:00 2001 From: Gyoungmin Kim Date: Sat, 27 Jul 2024 15:09:08 +0900 Subject: [PATCH 3/4] refactor: add hasOwnerMemberId in photo service --- .../main/java/kr/mafoo/photo/service/PhotoService.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 be3d734..1fe2f14 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 @@ -7,10 +7,12 @@ import kr.mafoo.photo.repository.PhotoRepository; import kr.mafoo.photo.util.IdGenerator; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; +@Slf4j @RequiredArgsConstructor @Service public class PhotoService { @@ -66,7 +68,8 @@ public Mono updatePhotoAlbumId(String photoId, String albumId, Stri .findById(photoId) .switchIfEmpty(Mono.error(new PhotoNotFoundException())) .flatMap(photoEntity -> { - if (photoEntity.getOwnerMemberId() == null) { + + if (!hasOwnerId(photoEntity)) { photoRepository.save(photoEntity.updateOwnerMemberId(requestMemberId)); } @@ -91,4 +94,8 @@ public Mono updatePhotoAlbumId(String photoId, String albumId, Stri }); } + private Boolean hasOwnerId(PhotoEntity photoEntity) { + return photoEntity.getOwnerMemberId() != null; + } + } From 9f6833b1aa36283eec92e7cd7d1de2aca1305ec4 Mon Sep 17 00:00:00 2001 From: Gyoungmin Kim Date: Sun, 28 Jul 2024 14:16:04 +0900 Subject: [PATCH 4/4] refactor: add hasOwnerMemberId in photo entity --- .../src/main/java/kr/mafoo/photo/domain/PhotoEntity.java | 4 ++++ .../src/main/java/kr/mafoo/photo/service/PhotoService.java | 6 +----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/photo-service/src/main/java/kr/mafoo/photo/domain/PhotoEntity.java b/photo-service/src/main/java/kr/mafoo/photo/domain/PhotoEntity.java index dd908ce..6785e82 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/domain/PhotoEntity.java +++ b/photo-service/src/main/java/kr/mafoo/photo/domain/PhotoEntity.java @@ -62,6 +62,10 @@ public String getId() { return photoId; } + public Boolean hasOwnerMemberId() { + return this.getOwnerMemberId() != null; + } + public PhotoEntity updateOwnerMemberId(String ownerMemberId) { this.ownerMemberId = ownerMemberId; return this; 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 1fe2f14..aa20342 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 @@ -69,7 +69,7 @@ public Mono updatePhotoAlbumId(String photoId, String albumId, Stri .switchIfEmpty(Mono.error(new PhotoNotFoundException())) .flatMap(photoEntity -> { - if (!hasOwnerId(photoEntity)) { + if (!photoEntity.hasOwnerMemberId()) { photoRepository.save(photoEntity.updateOwnerMemberId(requestMemberId)); } @@ -94,8 +94,4 @@ public Mono updatePhotoAlbumId(String photoId, String albumId, Stri }); } - private Boolean hasOwnerId(PhotoEntity photoEntity) { - return photoEntity.getOwnerMemberId() != null; - } - }