Skip to content

Commit

Permalink
Merge pull request #52 from YAPP-Github/MAFOO-38
Browse files Browse the repository at this point in the history
[MAFOO-38] feat: μ‚¬μ§„μ˜ 앨범 정보 등둝 (사진 앨범 id λ³€κ²½) μ‹œ μ†Œμœ μžκ°€ μ—†λŠ” μ‚¬μ§„μ˜ μ†Œμœ μž ν• λ‹Ή 둜직 μΆ”κ°€
  • Loading branch information
gmkim20713 authored Jul 28, 2024
2 parents a16f704 + 9f6833b commit e5c460d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ public String getId() {
return photoId;
}

public Boolean hasOwnerMemberId() {
return this.getOwnerMemberId() != null;
}

public PhotoEntity updateOwnerMemberId(String ownerMemberId) {
this.ownerMemberId = ownerMemberId;
return this;
}

public PhotoEntity updateAlbumId(String albumId) {
this.albumId = albumId;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
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 org.springframework.transaction.annotation.Transactional;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@Slf4j
@RequiredArgsConstructor
@Service
public class PhotoService {
Expand Down Expand Up @@ -39,7 +41,7 @@ public Flux<PhotoEntity> 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 {
Expand All @@ -54,7 +56,7 @@ public Mono<Void> 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 {
Expand All @@ -70,15 +72,20 @@ public Mono<PhotoEntity> updatePhotoAlbumId(String photoId, String albumId, Stri
.findById(photoId)
.switchIfEmpty(Mono.error(new PhotoNotFoundException()))
.flatMap(photoEntity -> {
if(!photoEntity.getOwnerMemberId().equals(requestMemberId)) {

if (!photoEntity.hasOwnerMemberId()) {
photoRepository.save(photoEntity.updateOwnerMemberId(requestMemberId));
}

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)) {
if (!albumEntity.getOwnerMemberId().equals(requestMemberId)) {
// λ‚΄ 앨범이 μ•„λ‹ˆλ©΄ κ·Έλƒ₯ μ—†λŠ” 앨범 처리
return Mono.error(new AlbumNotFoundException());
} else {
Expand Down

0 comments on commit e5c460d

Please sign in to comment.