Skip to content

Commit

Permalink
Merge pull request #70 from YAPP-Github/feature/MAFOO-173
Browse files Browse the repository at this point in the history
[MAFOO-173] feat: ์ด๋ฏธ์ง€ ํŒŒ์ผ ์—…๋กœ๋“œ API์˜ ์•จ๋ฒ” ๊ด€๋ จ ์š”์†Œ(photoCount, albumId) ์—…๋ฐ์ดํŠธ ๋กœ์ง์„ ์ถ”๊ฐ€ํ–ˆ์–ด์š”
  • Loading branch information
gmkim20713 authored Oct 26, 2024
2 parents a4d047c + 3ddada2 commit c80ad4c
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Flux<PhotoResponse> uploadFileUrlPhoto(
PhotoFileUrlUploadRequest request
){
return photoService
.createNewPhotoFileUrl(request.fileUrls(), memberId)
.createNewPhotoFileUrls(request.fileUrls(), request.albumId(), memberId)
.map(PhotoResponse::fromEntity);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@

import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Schema;
import kr.mafoo.photo.annotation.ULID;

@Schema(description = "ํŒŒ์ผ(url) ์‚ฌ์ง„ n๊ฑด ์—…๋กœ๋“œ ์š”์ฒญ")
public record PhotoFileUrlUploadRequest(
@ArraySchema(
schema = @Schema(description = "ํŒŒ์ผ URL ๋ชฉ๋ก"),
arraySchema = @Schema(example = "[\"file_url_1\", \"file_url_2\", \"file_url_3\"]")
)
String[] fileUrls
String[] fileUrls,

@ULID
@Schema(description = "์•จ๋ฒ” ID", example = "test_album_id")
String albumId
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ public AlbumEntity updateType(AlbumType newType) {
return this;
}

public AlbumEntity increasePhotoCount() {
this.photoCount += 1;
public AlbumEntity increasePhotoCount(int count) {
this.photoCount += count;
return this;
}

public AlbumEntity decreasePhotoCount() {
this.photoCount -= 1;
public AlbumEntity decreasePhotoCount(int count) {
this.photoCount -= count;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,14 @@ public PhotoEntity updateDisplayIndex(Integer displayIndex) {
return this;
}

public static PhotoEntity newPhoto(String photoId, String photoUrl, BrandType brandType, String ownerMemberId) {
public static PhotoEntity newPhoto(String photoId, String photoUrl, BrandType brandType, String albumId, Integer displayIndex, String ownerMemberId) {
PhotoEntity photo = new PhotoEntity();
photo.photoId = photoId;
photo.photoUrl = photoUrl;
photo.brand = brandType;
photo.ownerMemberId = ownerMemberId;
photo.displayIndex = 0;
photo.albumId = albumId;
photo.displayIndex = displayIndex;
photo.isNew = true;
photo.createdAt = LocalDateTime.now();
photo.updatedAt = LocalDateTime.now();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,85 +67,39 @@ public Mono<AlbumEntity> findByAlbumId(String albumId, String requestMemberId) {

@Transactional
public Mono<Void> deleteAlbumById(String albumId, String requestMemberId) {
return albumRepository
.findById(albumId)
.switchIfEmpty(Mono.error(new AlbumNotFoundException()))
.flatMap(albumEntity -> {
if(!albumEntity.getOwnerMemberId().equals(requestMemberId)) {
// ๋‚ด ์•จ๋ฒ”์ด ์•„๋‹ˆ๋ฉด ๊ทธ๋ƒฅ ์—†๋Š” ์•จ๋ฒ” ์ฒ˜๋ฆฌ
return Mono.error(new AlbumNotFoundException());
} else {
return albumRepository
return findByAlbumId(albumId, requestMemberId)
.flatMap(albumEntity ->
albumRepository
.deleteById(albumId)
.then(albumRepository.popDisplayIndexBetween(
requestMemberId, albumEntity.getDisplayIndex(), Integer.MAX_VALUE));
}
});
requestMemberId, albumEntity.getDisplayIndex(), Integer.MAX_VALUE))
);
}

@Transactional
public Mono<AlbumEntity> updateAlbumName(String albumId, String albumName, String requestMemberId) {
return albumRepository
.findById(albumId)
.switchIfEmpty(Mono.error(new AlbumNotFoundException()))
.flatMap(albumEntity -> {
if(!albumEntity.getOwnerMemberId().equals(requestMemberId)) {
// ๋‚ด ์•จ๋ฒ”์ด ์•„๋‹ˆ๋ฉด ๊ทธ๋ƒฅ ์—†๋Š” ์•จ๋ฒ” ์ฒ˜๋ฆฌ
return Mono.error(new AlbumNotFoundException());
} else {
return albumRepository.save(albumEntity.updateName(albumName));
}
});
return findByAlbumId(albumId, requestMemberId)
.flatMap(albumEntity -> albumRepository.save(albumEntity.updateName(albumName)));
}

@Transactional
public Mono<AlbumEntity> updateAlbumType(String albumId, AlbumType albumType, String requestMemberId) {
return albumRepository
.findById(albumId)
.switchIfEmpty(Mono.error(new AlbumNotFoundException()))
.flatMap(albumEntity -> {
if(!albumEntity.getOwnerMemberId().equals(requestMemberId)) {
// ๋‚ด ์•จ๋ฒ”์ด ์•„๋‹ˆ๋ฉด ๊ทธ๋ƒฅ ์—†๋Š” ์•จ๋ฒ” ์ฒ˜๋ฆฌ
return Mono.error(new AlbumNotFoundException());
} else {
return albumRepository.save(albumEntity.updateType(albumType));
}
});
return findByAlbumId(albumId, requestMemberId)
.flatMap(albumEntity -> albumRepository.save(albumEntity.updateType(albumType)));
}

@Transactional
public Mono<Void> increaseAlbumPhotoCount(String albumId, String requestMemberId) {
return albumRepository
.findById(albumId)
.switchIfEmpty(Mono.error(new AlbumNotFoundException()))
.flatMap(albumEntity -> {
if (!albumEntity.getOwnerMemberId().equals(requestMemberId)) {
// ๋‚ด ์•จ๋ฒ”์ด ์•„๋‹ˆ๋ฉด ๊ทธ๋ƒฅ ์—†๋Š” ์•จ๋ฒ” ์ฒ˜๋ฆฌ
return Mono.error(new AlbumNotFoundException());
} else {
return albumRepository.save(albumEntity.increasePhotoCount()).then();
}
});
public Mono<AlbumEntity> increaseAlbumPhotoCount(String albumId, int count, String requestMemberId) {
return findByAlbumId(albumId, requestMemberId)
.flatMap(albumEntity -> albumRepository.save(albumEntity.increasePhotoCount(count)));
}

@Transactional
public Mono<Void> decreaseAlbumPhotoCount(String albumId, String requestMemberId) {

if (albumId == null) {
return Mono.empty();
}

return albumRepository
.findById(albumId)
.switchIfEmpty(Mono.error(new AlbumNotFoundException()))
.flatMap(albumEntity -> {
if (!albumEntity.getOwnerMemberId().equals(requestMemberId)) {
// ๋‚ด ์•จ๋ฒ”์ด ์•„๋‹ˆ๋ฉด ๊ทธ๋ƒฅ ์—†๋Š” ์•จ๋ฒ” ์ฒ˜๋ฆฌ
return Mono.error(new AlbumNotFoundException());
} else {
return albumRepository.save(albumEntity.decreasePhotoCount()).then();
}
});
public Mono<AlbumEntity> decreaseAlbumPhotoCount(String albumId, int count, String requestMemberId) {
return Mono.justOrEmpty(albumId)
.switchIfEmpty(Mono.empty())
.flatMap(id -> findByAlbumId(id, requestMemberId))
.flatMap(albumEntity -> albumRepository.save(albumEntity.decreasePhotoCount(count)));
}

}
Loading

0 comments on commit c80ad4c

Please sign in to comment.