diff --git a/photo-service/src/main/java/kr/mafoo/photo/controller/dto/response/AlbumResponse.java b/photo-service/src/main/java/kr/mafoo/photo/controller/dto/response/AlbumResponse.java index 9445b78..c665edf 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/controller/dto/response/AlbumResponse.java +++ b/photo-service/src/main/java/kr/mafoo/photo/controller/dto/response/AlbumResponse.java @@ -16,14 +16,14 @@ public record AlbumResponse( AlbumType type, @Schema(description = "앨범 내 사진 수", example = "6") - Long photoCount + String photoCount ) { public static AlbumResponse fromEntity(AlbumEntity entity) { return new AlbumResponse( entity.getAlbumId(), entity.getName(), entity.getType(), - entity.getPhotoCount() + "0" ); } } diff --git a/photo-service/src/main/java/kr/mafoo/photo/domain/AlbumEntity.java b/photo-service/src/main/java/kr/mafoo/photo/domain/AlbumEntity.java index f518025..245f22d 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/domain/AlbumEntity.java +++ b/photo-service/src/main/java/kr/mafoo/photo/domain/AlbumEntity.java @@ -42,9 +42,6 @@ public class AlbumEntity implements Persistable { @Transient private boolean isNew = false; - @Transient - private long photoCount = 0; - @Override public boolean equals(Object obj) { if (this == obj) return true; diff --git a/photo-service/src/main/java/kr/mafoo/photo/repository/PhotoRepository.java b/photo-service/src/main/java/kr/mafoo/photo/repository/PhotoRepository.java index 61e3b22..1af61d4 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/repository/PhotoRepository.java +++ b/photo-service/src/main/java/kr/mafoo/photo/repository/PhotoRepository.java @@ -3,9 +3,7 @@ import kr.mafoo.photo.domain.PhotoEntity; import org.springframework.data.r2dbc.repository.R2dbcRepository; import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; public interface PhotoRepository extends R2dbcRepository { Flux findAllByAlbumId(String ownerAlbumId); - Mono countAllByAlbumId(String albumId); -} +} \ No newline at end of file diff --git a/photo-service/src/main/java/kr/mafoo/photo/service/AlbumService.java b/photo-service/src/main/java/kr/mafoo/photo/service/AlbumService.java index 788209a..61e1bac 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/service/AlbumService.java +++ b/photo-service/src/main/java/kr/mafoo/photo/service/AlbumService.java @@ -4,7 +4,6 @@ import kr.mafoo.photo.domain.AlbumType; import kr.mafoo.photo.exception.AlbumNotFoundException; import kr.mafoo.photo.repository.AlbumRepository; -import kr.mafoo.photo.repository.PhotoRepository; import kr.mafoo.photo.util.IdGenerator; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -15,7 +14,6 @@ @Service public class AlbumService { private final AlbumRepository albumRepository; - private final PhotoRepository photoRepository; public Mono createNewAlbum(String ownerMemberId, String albumName, AlbumType albumType) { AlbumEntity albumEntity = AlbumEntity.newAlbum(IdGenerator.generate(), albumName, albumType, ownerMemberId); @@ -23,15 +21,7 @@ public Mono createNewAlbum(String ownerMemberId, String albumName, } public Flux findAllByOwnerMemberId(String ownerMemberId) { - return albumRepository - .findAllByOwnerMemberId(ownerMemberId) - .flatMap((albumEntity) -> photoRepository - .countAllByAlbumId(albumEntity.getId()) - .map(photoCount -> { - albumEntity.setPhotoCount(photoCount); - return albumEntity; - }) - ); + return albumRepository.findAllByOwnerMemberId(ownerMemberId); } public Mono findByAlbumId(String albumId, String requestMemberId) { @@ -39,15 +29,12 @@ public Mono findByAlbumId(String albumId, String requestMemberId) { .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 { return Mono.just(albumEntity); } - }).zipWith(photoRepository.countAllByAlbumId(albumId), (album, albumCount) -> { - album.setPhotoCount(albumCount); - return album; }); } @@ -56,7 +43,7 @@ public Mono deleteAlbumById(String albumId, String requestMemberId) { .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 { @@ -70,7 +57,7 @@ public Mono updateAlbumName(String albumId, String albumName, Strin .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 { @@ -84,7 +71,7 @@ public Mono updateAlbumType(String albumId, AlbumType albumType, St .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 {