diff --git a/umbba-api/src/main/java/sopt/org/umbba/api/controller/album/AlbumController.java b/umbba-api/src/main/java/sopt/org/umbba/api/controller/album/AlbumController.java index d8eddaae..d0f46a1f 100644 --- a/umbba-api/src/main/java/sopt/org/umbba/api/controller/album/AlbumController.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/controller/album/AlbumController.java @@ -1,6 +1,7 @@ package sopt.org.umbba.api.controller.album; import static sopt.org.umbba.api.config.jwt.JwtProvider.*; +import static sopt.org.umbba.api.service.album.AlbumService.*; import static sopt.org.umbba.common.exception.SuccessType.*; import static sopt.org.umbba.external.s3.S3BucketPrefix.*; @@ -60,7 +61,9 @@ public ApiResponse getImgPreSignedUrl(@RequestBody final AlbumI @ResponseStatus(HttpStatus.OK) public ApiResponse deleteAlbum(@PathVariable final Long albumId, final Principal principal) { String imgUrl = albumService.deleteAlbum(albumId, getUserFromPrincial(principal)); - s3Service.deleteS3Image(imgUrl); + if (!imgUrl.equals(ALBUM_EXAMPLE)) { // Example Album의 이미지는 삭제하지 X + s3Service.deleteS3Image(imgUrl); + } return ApiResponse.success(DELETE_ALBUM_SUCCESS); } diff --git a/umbba-api/src/main/java/sopt/org/umbba/api/service/album/AlbumService.java b/umbba-api/src/main/java/sopt/org/umbba/api/service/album/AlbumService.java index d9a1a261..b2f00420 100644 --- a/umbba-api/src/main/java/sopt/org/umbba/api/service/album/AlbumService.java +++ b/umbba-api/src/main/java/sopt/org/umbba/api/service/album/AlbumService.java @@ -25,12 +25,23 @@ public class AlbumService { private final AlbumRepository albumRepository; private final UserRepository userRepository; + public static final String ALBUM_EXAMPLE = "example"; + @Transactional public Long createAlbum(final CreateAlbumRequestDto request, final String imgUrl, final Long userId) { User user = getUserById(userId); Parentchild parentchild = getParentchildByUser(user); + if (parentchild.isOverMaxAlbumLimit()) { + throw new CustomException(ErrorType.MAX_LIMIT_ALBUM_UPLOAD); + } + + // 앨범을 처음 등록하는 경우 + if (parentchild.getAlbumList().isEmpty() && !parentchild.isFirstAlbumUpload()) { + parentchild.updateFirstAlbumUpload(); + } + Album album = Album.builder() .title(request.getTitle()) .content(request.getContent()) @@ -50,6 +61,13 @@ public String deleteAlbum(final Long albumId, final Long userId) { User user = getUserById(userId); Parentchild parentchild = getParentchildByUser(user); + + // Sample Album을 삭제할 경우 + if (albumId.equals(0L)) { + parentchild.updateDeleteSampleAlbum(); + return ALBUM_EXAMPLE; + } + Album album = getAlbumById(albumId); album.deleteParentchild(); @@ -65,11 +83,21 @@ public List getAlbumList(final Long userId) { List albumList = albumRepository.findAllByParentchildOrderByCreatedAtDesc( parentchild); + // Album을 아직 한번도 등록하지 않은 경우 + if (albumList.isEmpty() && !parentchild.isFirstAlbumUpload() && !parentchild.isDeleteSampleAlbum()) { + return List.of(AlbumResponseDto.of(createAlbumExample())); + } + return albumList.stream() .map(AlbumResponseDto::of) .collect(Collectors.toList()); } + private Album createAlbumExample() { + return new Album(0L, "사진의 제목을 입력할 수 있어요", "사진에 대해 소개해요", + "imgUrl", "직성자"); + } + private User getUserById(Long userId) { // TODO userId -> Parentchild 한번에 가져오기 return userRepository.findById(userId).orElseThrow( () -> new CustomException(ErrorType.INVALID_USER) diff --git a/umbba-common/src/main/java/sopt/org/umbba/common/exception/ErrorType.java b/umbba-common/src/main/java/sopt/org/umbba/common/exception/ErrorType.java index a026cf50..c6dab332 100644 --- a/umbba-common/src/main/java/sopt/org/umbba/common/exception/ErrorType.java +++ b/umbba-common/src/main/java/sopt/org/umbba/common/exception/ErrorType.java @@ -105,6 +105,8 @@ public enum ErrorType { * 501 NOT_IMPLEMENTED */ NEED_MORE_QUESTION(HttpStatus.NOT_IMPLEMENTED, "남은 질문이 없습니다. 질문을 추가해주세요."), + MAX_LIMIT_ALBUM_UPLOAD(HttpStatus.NOT_IMPLEMENTED, "한 부모자식마다 최대 15개의 업로드까지만 허용합니다."), + ; diff --git a/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/album/Album.java b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/album/Album.java index 342cccb3..1217db48 100644 --- a/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/album/Album.java +++ b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/album/Album.java @@ -52,6 +52,14 @@ private Album(String title, String content, String imgUrl, String writer, Parent this.parentchild = parentchild; } + public Album(Long id, String title, String content, String imgUrl, String writer) { + this.id = id; + this.title = title; + this.content = content; + this.imgUrl = imgUrl; + this.writer = writer; + } + public void setParentchild(Parentchild parentchild) { this.parentchild = parentchild; diff --git a/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/parentchild/Parentchild.java b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/parentchild/Parentchild.java index ca6010e5..b53aff2f 100644 --- a/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/parentchild/Parentchild.java +++ b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/parentchild/Parentchild.java @@ -112,6 +112,18 @@ public void changeParentOnboardingAnswerList(List onboardingAn private boolean deleted = Boolean.FALSE; + private boolean isFirstAlbumUpload = false; + + private boolean isDeleteSampleAlbum = false; + + public void updateFirstAlbumUpload() { + this.isFirstAlbumUpload = true; + } + public void updateDeleteSampleAlbum() { + this.isDeleteSampleAlbum = true; + } + + public void setQna(QnA qnA) { if (qnaList.size() >= 7) { throw new CustomException(ErrorType.ALREADY_QNA_LIST_FULL); @@ -136,4 +148,8 @@ public void deleteAlbum(Album album) { } } + public boolean isOverMaxAlbumLimit() { + return getAlbumList().size() >= 15; + } + }