Skip to content

Commit

Permalink
Revert "feat: add photo count to album"
Browse files Browse the repository at this point in the history
This reverts commit 9eacb5e.
  • Loading branch information
CChuYong committed Jul 19, 2024
1 parent 9eacb5e commit d603fff
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ public class AlbumEntity implements Persistable<String> {
@Transient
private boolean isNew = false;

@Transient
private long photoCount = 0;

@Override
public boolean equals(Object obj) {
if (this == obj) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<PhotoEntity, String> {
Flux<PhotoEntity> findAllByAlbumId(String ownerAlbumId);
Mono<Long> countAllByAlbumId(String albumId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,39 +14,27 @@
@Service
public class AlbumService {
private final AlbumRepository albumRepository;
private final PhotoRepository photoRepository;

public Mono<AlbumEntity> createNewAlbum(String ownerMemberId, String albumName, AlbumType albumType) {
AlbumEntity albumEntity = AlbumEntity.newAlbum(IdGenerator.generate(), albumName, albumType, ownerMemberId);
return albumRepository.save(albumEntity);
}

public Flux<AlbumEntity> 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<AlbumEntity> findByAlbumId(String albumId, String requestMemberId) {
return albumRepository
.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;
});
}

Expand All @@ -56,7 +43,7 @@ public Mono<Void> 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 {
Expand All @@ -70,7 +57,7 @@ public Mono<AlbumEntity> 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 {
Expand All @@ -84,7 +71,7 @@ public Mono<AlbumEntity> 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 {
Expand Down

0 comments on commit d603fff

Please sign in to comment.