From a5a01743704eeaff67bc8cd23df3beae4690a281 Mon Sep 17 00:00:00 2001 From: jun02160 Date: Sun, 10 Mar 2024 03:21:31 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[FEAT]=20=EC=B5=9C=EB=8C=80=20=EC=97=85?= =?UTF-8?q?=EB=A1=9C=EB=93=9C=20=ED=97=88=EC=9A=A9=20limit=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20#138?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/sopt/org/umbba/api/service/album/AlbumService.java | 4 ++++ .../main/java/sopt/org/umbba/common/exception/ErrorType.java | 2 ++ .../sopt/org/umbba/domain/domain/parentchild/Parentchild.java | 4 ++++ 3 files changed, 10 insertions(+) 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..2ed9d5a2 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 @@ -31,6 +31,10 @@ public Long createAlbum(final CreateAlbumRequestDto request, final String imgUrl User user = getUserById(userId); Parentchild parentchild = getParentchildByUser(user); + if (parentchild.isOverMaxAlbumLimit()) { + throw new CustomException(ErrorType.MAX_LIMIT_ALBUM_UPLOAD); + } + Album album = Album.builder() .title(request.getTitle()) .content(request.getContent()) 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/parentchild/Parentchild.java b/umbba-domain/src/main/java/sopt/org/umbba/domain/domain/parentchild/Parentchild.java index ca6010e5..47c71539 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 @@ -136,4 +136,8 @@ public void deleteAlbum(Album album) { } } + public boolean isOverMaxAlbumLimit() { + return getAlbumList().size() >= 15; + } + } From b67ef0500698bb52dcc6521ab02b1117debc90da Mon Sep 17 00:00:00 2001 From: jun02160 Date: Sun, 10 Mar 2024 03:42:27 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[FEAT]=20Album=20=ED=8A=9C=ED=86=A0?= =?UTF-8?q?=EB=A6=AC=EC=96=BC=EC=9A=A9=20Example=20=EC=B6=94=EA=B0=80=20#1?= =?UTF-8?q?38?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../umbba/api/service/album/AlbumService.java | 20 +++++++++++++++++++ .../domain/parentchild/Parentchild.java | 6 ++++++ 2 files changed, 26 insertions(+) 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 2ed9d5a2..b946e5e3 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 @@ -35,6 +35,11 @@ public Long createAlbum(final CreateAlbumRequestDto request, final String imgUrl 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()) @@ -69,11 +74,26 @@ public List getAlbumList(final Long userId) { List albumList = albumRepository.findAllByParentchildOrderByCreatedAtDesc( parentchild); + // Album을 아직 한번도 등록하지 않은 경우 + if (albumList.isEmpty() && !parentchild.isFirstAlbumUpload()) { + return List.of(AlbumResponseDto.of(createAlbumExample(parentchild))); + } + return albumList.stream() .map(AlbumResponseDto::of) .collect(Collectors.toList()); } + private Album createAlbumExample(Parentchild parentchild) { + return Album.builder() + .title("사진의 제목을 입력할 수 있어요") + .content("사진에 대해 소개해요") + .imgUrl("imgUrl") + .writer("직성자") + .parentchild(parentchild) + .build(); + } + private User getUserById(Long userId) { // TODO userId -> Parentchild 한번에 가져오기 return userRepository.findById(userId).orElseThrow( () -> new CustomException(ErrorType.INVALID_USER) 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 47c71539..5b2dc3e1 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,12 @@ public void changeParentOnboardingAnswerList(List onboardingAn private boolean deleted = Boolean.FALSE; + private boolean isFirstAlbumUpload = false; + + public void updateFirstAlbumUpload() { + this.isFirstAlbumUpload = true; + } + public void setQna(QnA qnA) { if (qnaList.size() >= 7) { throw new CustomException(ErrorType.ALREADY_QNA_LIST_FULL); From f8a69a82176df84523ec98851ac89e877686f449 Mon Sep 17 00:00:00 2001 From: jun02160 Date: Sun, 10 Mar 2024 04:22:31 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[FEAT]=20Album=20=ED=8A=9C=ED=86=A0?= =?UTF-8?q?=EB=A6=AC=EC=96=BC=EC=9A=A9=20Example=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20#138?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../umbba/api/service/album/AlbumService.java | 21 ++++++++++--------- .../org/umbba/domain/domain/album/Album.java | 8 +++++++ .../domain/parentchild/Parentchild.java | 6 ++++++ 3 files changed, 25 insertions(+), 10 deletions(-) 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 b946e5e3..98d805e4 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 @@ -59,6 +59,12 @@ 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(); + } + Album album = getAlbumById(albumId); album.deleteParentchild(); @@ -75,8 +81,8 @@ public List getAlbumList(final Long userId) { parentchild); // Album을 아직 한번도 등록하지 않은 경우 - if (albumList.isEmpty() && !parentchild.isFirstAlbumUpload()) { - return List.of(AlbumResponseDto.of(createAlbumExample(parentchild))); + if (albumList.isEmpty() && !parentchild.isFirstAlbumUpload() && !parentchild.isDeleteSampleAlbum()) { + return List.of(AlbumResponseDto.of(createAlbumExample())); } return albumList.stream() @@ -84,14 +90,9 @@ public List getAlbumList(final Long userId) { .collect(Collectors.toList()); } - private Album createAlbumExample(Parentchild parentchild) { - return Album.builder() - .title("사진의 제목을 입력할 수 있어요") - .content("사진에 대해 소개해요") - .imgUrl("imgUrl") - .writer("직성자") - .parentchild(parentchild) - .build(); + private Album createAlbumExample() { + return new Album(0L, "사진의 제목을 입력할 수 있어요", "사진에 대해 소개해요", + "imgUrl", "직성자"); } private User getUserById(Long userId) { // TODO userId -> Parentchild 한번에 가져오기 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 5b2dc3e1..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 @@ -114,9 +114,15 @@ public void changeParentOnboardingAnswerList(List onboardingAn 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) { From 66c0253bbd35ec6fa46699781e1be19cceb7646a Mon Sep 17 00:00:00 2001 From: jun02160 Date: Sun, 10 Mar 2024 04:34:37 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[FIX]=20Album=20Example=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=EC=97=90=20=EB=94=B0=EB=A5=B8=20=EB=B6=84=EA=B8=B0?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20#138?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopt/org/umbba/api/controller/album/AlbumController.java | 5 ++++- .../java/sopt/org/umbba/api/service/album/AlbumService.java | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) 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 98d805e4..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,6 +25,8 @@ 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) { @@ -63,6 +65,7 @@ public String deleteAlbum(final Long albumId, final Long userId) { // Sample Album을 삭제할 경우 if (albumId.equals(0L)) { parentchild.updateDeleteSampleAlbum(); + return ALBUM_EXAMPLE; } Album album = getAlbumById(albumId);