From ce21481c8eacbc611ace4d229d314fd04d369d7b Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sat, 16 Nov 2024 19:24:04 +0900 Subject: [PATCH 01/41] =?UTF-8?q?refactor:=20requestPart=EB=A1=9C=20multip?= =?UTF-8?q?art=20file=EC=9D=84=20=EB=B0=9B=EB=8D=98=20=EA=B2=83=EC=9D=84?= =?UTF-8?q?=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../board/presentation/NoticeAdminController.java | 14 ++++++-------- .../domain/board/presentation/PostController.java | 14 ++++++-------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/main/java/leets/weeth/domain/board/presentation/NoticeAdminController.java b/src/main/java/leets/weeth/domain/board/presentation/NoticeAdminController.java index f1cebc3e..de5b3c70 100644 --- a/src/main/java/leets/weeth/domain/board/presentation/NoticeAdminController.java +++ b/src/main/java/leets/weeth/domain/board/presentation/NoticeAdminController.java @@ -26,22 +26,20 @@ public class NoticeAdminController { private final NoticeUsecase noticeUsecase; - @PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + @PostMapping @Operation(summary="공지사항 생성") - public CommonResponse save(@RequestPart @Valid NoticeDTO.Save dto, - @RequestPart(value = "files", required = false) List files, + public CommonResponse save(@RequestBody @Valid NoticeDTO.Save dto, @Parameter(hidden = true) @CurrentUser Long userId) { - noticeUsecase.save(dto, files, userId); + noticeUsecase.save(dto, userId); return CommonResponse.createSuccess(NOTICE_CREATED_SUCCESS.getMessage()); } - @PatchMapping(value = "/{noticeId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + @PatchMapping(value = "/{noticeId}") @Operation(summary="특정 공지사항 수정") public CommonResponse update(@PathVariable Long noticeId, - @RequestPart @Valid NoticeDTO.Update dto, - @RequestPart(value = "files", required = false) List files, + @RequestBody @Valid NoticeDTO.Update dto, @Parameter(hidden = true) @CurrentUser Long userId) throws UserNotMatchException { - noticeUsecase.update(noticeId, dto, files, userId); + noticeUsecase.update(noticeId, dto, userId); return CommonResponse.createSuccess(NOTICE_UPDATED_SUCCESS.getMessage()); } diff --git a/src/main/java/leets/weeth/domain/board/presentation/PostController.java b/src/main/java/leets/weeth/domain/board/presentation/PostController.java index fd32dcb2..1c512910 100644 --- a/src/main/java/leets/weeth/domain/board/presentation/PostController.java +++ b/src/main/java/leets/weeth/domain/board/presentation/PostController.java @@ -26,12 +26,11 @@ public class PostController { private final PostUsecase postUsecase; - @PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + @PostMapping @Operation(summary="게시글 생성") - public CommonResponse save(@RequestPart @Valid PostDTO.Save dto, - @RequestPart(value = "files", required = false) List files, + public CommonResponse save(@RequestBody @Valid PostDTO.Save dto, @Parameter(hidden = true) @CurrentUser Long userId) { - postUsecase.save(dto, files, userId); + postUsecase.save(dto, userId); return CommonResponse.createSuccess(POST_CREATED_SUCCESS.getMessage()); } @@ -47,13 +46,12 @@ public CommonResponse findPost(@PathVariable Long postId) { return CommonResponse.createSuccess(POST_FIND_BY_ID_SUCCESS.getMessage(),postUsecase.findPost(postId)); } - @PatchMapping(value = "/{postId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + @PatchMapping(value = "/{postId}") @Operation(summary="특정 게시글 수정") public CommonResponse update(@PathVariable Long postId, - @RequestPart @Valid PostDTO.Update dto, - @RequestPart(value = "files", required = false) List files, + @RequestBody @Valid PostDTO.Update dto, @Parameter(hidden = true) @CurrentUser Long userId) throws UserNotMatchException { - postUsecase.update(postId, dto, files, userId); + postUsecase.update(postId, dto, userId); return CommonResponse.createSuccess(POST_UPDATED_SUCCESS.getMessage()); } From 387d5677e641ad5706dbbb2a874c0f94820c02ac Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sat, 16 Nov 2024 19:28:02 +0900 Subject: [PATCH 02/41] =?UTF-8?q?refactor:=20currentUser=20=EC=BB=A4?= =?UTF-8?q?=EC=8A=A4=ED=85=80=20=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EC=85=98=EC=97=90=EC=84=9C=20=EC=9D=B8=EC=A6=9D=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=EA=B0=80=20=EC=97=86=EB=8A=94=20=EA=B2=BD=EC=9A=B0=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=20=EB=8D=98=EC=A7=80=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jwt/exception/AnonymousAuthenticationException.java | 9 +++++++++ .../auth/resolver/CurrentUserArgumentResolver.java | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 src/main/java/leets/weeth/global/auth/jwt/exception/AnonymousAuthenticationException.java diff --git a/src/main/java/leets/weeth/global/auth/jwt/exception/AnonymousAuthenticationException.java b/src/main/java/leets/weeth/global/auth/jwt/exception/AnonymousAuthenticationException.java new file mode 100644 index 00000000..7cc77451 --- /dev/null +++ b/src/main/java/leets/weeth/global/auth/jwt/exception/AnonymousAuthenticationException.java @@ -0,0 +1,9 @@ +package leets.weeth.global.auth.jwt.exception; + +import leets.weeth.global.common.exception.BusinessLogicException; + +public class AnonymousAuthenticationException extends BusinessLogicException { + public AnonymousAuthenticationException() { + super(401, "인증정보가 존재하지 않습니다."); + } +} diff --git a/src/main/java/leets/weeth/global/auth/resolver/CurrentUserArgumentResolver.java b/src/main/java/leets/weeth/global/auth/resolver/CurrentUserArgumentResolver.java index 056ec5e8..f775e374 100644 --- a/src/main/java/leets/weeth/global/auth/resolver/CurrentUserArgumentResolver.java +++ b/src/main/java/leets/weeth/global/auth/resolver/CurrentUserArgumentResolver.java @@ -1,6 +1,7 @@ package leets.weeth.global.auth.resolver; import leets.weeth.global.auth.annotation.CurrentUser; +import leets.weeth.global.auth.jwt.exception.AnonymousAuthenticationException; import leets.weeth.global.auth.jwt.service.JwtService; import lombok.RequiredArgsConstructor; import org.springframework.core.MethodParameter; @@ -31,7 +32,7 @@ public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer m Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); // 인증 객체 가져오기 if (authentication instanceof AnonymousAuthenticationToken) { // 익명 인증 토큰의 인스턴스라면 0 반환 - return 0; + throw new AnonymousAuthenticationException(); } String token = Optional.ofNullable(webRequest.getHeader("Authorization")) From f4602da01cc78cc5991f5d25c85e3853a6456307 Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sat, 16 Nov 2024 19:28:31 +0900 Subject: [PATCH 03/41] =?UTF-8?q?refactor:=20notice,=20post=20=EC=97=85?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=8A=B8=20=EC=8B=9C=20fileUrl=EC=9D=84=20?= =?UTF-8?q?=EB=B0=9B=EC=A7=80=20=EC=95=8A=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/leets/weeth/domain/board/domain/entity/Notice.java | 4 ++-- .../java/leets/weeth/domain/board/domain/entity/Post.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/leets/weeth/domain/board/domain/entity/Notice.java b/src/main/java/leets/weeth/domain/board/domain/entity/Notice.java index 010c0809..f7f6e327 100644 --- a/src/main/java/leets/weeth/domain/board/domain/entity/Notice.java +++ b/src/main/java/leets/weeth/domain/board/domain/entity/Notice.java @@ -30,8 +30,8 @@ public void addComment(Comment comment) { comments.add(comment); } - public void update(NoticeDTO.Update dto, List fileUrls){ - this.updateUpperClass(dto, fileUrls); + public void update(NoticeDTO.Update dto){ + this.updateUpperClass(dto); } } diff --git a/src/main/java/leets/weeth/domain/board/domain/entity/Post.java b/src/main/java/leets/weeth/domain/board/domain/entity/Post.java index 5a713594..82e14e41 100644 --- a/src/main/java/leets/weeth/domain/board/domain/entity/Post.java +++ b/src/main/java/leets/weeth/domain/board/domain/entity/Post.java @@ -30,8 +30,8 @@ public void addComment(Comment comment) { comments.add(comment); } - public void update(PostDTO.Update dto, List fileUrls) { - this.updateUpperClass(dto, fileUrls); + public void update(PostDTO.Update dto) { + this.updateUpperClass(dto); } } From b25b45494c1c421a22422410fd1689818dcd51ba Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sat, 16 Nov 2024 19:29:17 +0900 Subject: [PATCH 04/41] =?UTF-8?q?refactor:=20notice,=20post=20=EA=B0=9D?= =?UTF-8?q?=EC=B2=B4=20=EC=83=9D=EC=84=B1=EC=8B=9C=20fileUrls=EB=A5=BC=20?= =?UTF-8?q?=EB=B0=9B=EC=A7=80=20=EC=95=8A=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weeth/domain/board/application/mapper/NoticeMapper.java | 2 +- .../leets/weeth/domain/board/application/mapper/PostMapper.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/leets/weeth/domain/board/application/mapper/NoticeMapper.java b/src/main/java/leets/weeth/domain/board/application/mapper/NoticeMapper.java index 8dff57f7..34106305 100644 --- a/src/main/java/leets/weeth/domain/board/application/mapper/NoticeMapper.java +++ b/src/main/java/leets/weeth/domain/board/application/mapper/NoticeMapper.java @@ -19,7 +19,7 @@ public interface NoticeMapper { @Mapping(target = "id", ignore = true), @Mapping(target = "user", source = "user") }) - Notice fromNoticeDto(NoticeDTO.Save dto, List fileUrls, User user); + Notice fromNoticeDto(NoticeDTO.Save dto, User user); @Mappings({ @Mapping(target = "name", source = "user.name"), diff --git a/src/main/java/leets/weeth/domain/board/application/mapper/PostMapper.java b/src/main/java/leets/weeth/domain/board/application/mapper/PostMapper.java index ecb55f77..78a5c251 100644 --- a/src/main/java/leets/weeth/domain/board/application/mapper/PostMapper.java +++ b/src/main/java/leets/weeth/domain/board/application/mapper/PostMapper.java @@ -19,7 +19,7 @@ public interface PostMapper { @Mapping(target = "id", ignore = true), @Mapping(target = "user", source = "user") }) - Post fromPostDto(PostDTO.Save dto, List fileUrls, User user); + Post fromPostDto(PostDTO.Save dto, User user); @Mappings({ @Mapping(target = "name", source = "user.name"), From 17064ce6d943e514a7c9f90b0cadf4623d550b26 Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sat, 16 Nov 2024 19:29:37 +0900 Subject: [PATCH 05/41] =?UTF-8?q?refactor:=20notice,=20post=20=EA=B0=9D?= =?UTF-8?q?=EC=B2=B4=20=EC=83=9D=EC=84=B1,=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=EC=97=90=20file=20=EA=B4=80=EB=A0=A8=20dto?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weeth/domain/board/application/dto/NoticeDTO.java | 8 ++++++-- .../leets/weeth/domain/board/application/dto/PostDTO.java | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/leets/weeth/domain/board/application/dto/NoticeDTO.java b/src/main/java/leets/weeth/domain/board/application/dto/NoticeDTO.java index 8ed9b3ca..21cf1672 100644 --- a/src/main/java/leets/weeth/domain/board/application/dto/NoticeDTO.java +++ b/src/main/java/leets/weeth/domain/board/application/dto/NoticeDTO.java @@ -2,6 +2,8 @@ import jakarta.validation.constraints.NotNull; import leets.weeth.domain.comment.application.dto.CommentDTO; +import leets.weeth.domain.file.application.dto.request.FileSaveRequest; +import leets.weeth.domain.file.application.dto.request.FileUpdateRequest; import lombok.Builder; import java.time.LocalDateTime; @@ -12,13 +14,15 @@ public class NoticeDTO { @Builder public record Save( @NotNull String title, - @NotNull String content + @NotNull String content, + List files ){} @Builder public record Update( @NotNull String title, - @NotNull String content + @NotNull String content, + List files ){} @Builder diff --git a/src/main/java/leets/weeth/domain/board/application/dto/PostDTO.java b/src/main/java/leets/weeth/domain/board/application/dto/PostDTO.java index 450271f4..4c0f1295 100644 --- a/src/main/java/leets/weeth/domain/board/application/dto/PostDTO.java +++ b/src/main/java/leets/weeth/domain/board/application/dto/PostDTO.java @@ -2,6 +2,8 @@ import jakarta.validation.constraints.NotNull; import leets.weeth.domain.comment.application.dto.CommentDTO; +import leets.weeth.domain.file.application.dto.request.FileSaveRequest; +import leets.weeth.domain.file.application.dto.request.FileUpdateRequest; import lombok.Builder; import java.time.LocalDateTime; @@ -12,13 +14,15 @@ public class PostDTO { @Builder public record Save( @NotNull String title, - @NotNull String content + @NotNull String content, + List files ){} @Builder public record Update( @NotNull String title, - @NotNull String content + @NotNull String content, + List files ){} @Builder From abb03ce7e96e33b097be70c309f380837fa6ccd6 Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sat, 16 Nov 2024 19:31:29 +0900 Subject: [PATCH 06/41] =?UTF-8?q?refactor:=20=ED=8A=B8=EB=9E=9C=EC=9E=AD?= =?UTF-8?q?=EC=85=98=EC=9D=84=20=EC=83=81=EC=9C=84=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EA=B1=B8=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../leets/weeth/domain/board/domain/service/PostSaveService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/leets/weeth/domain/board/domain/service/PostSaveService.java b/src/main/java/leets/weeth/domain/board/domain/service/PostSaveService.java index b5d6f6bc..80cd5b55 100644 --- a/src/main/java/leets/weeth/domain/board/domain/service/PostSaveService.java +++ b/src/main/java/leets/weeth/domain/board/domain/service/PostSaveService.java @@ -12,7 +12,6 @@ public class PostSaveService { private final PostRepository postRepository; - @Transactional public void save(Post post) { postRepository.save(post); } From 0565845561a7c2f196e5330dd06128ca902e3a64 Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sat, 16 Nov 2024 19:31:43 +0900 Subject: [PATCH 07/41] =?UTF-8?q?refactor:=20=ED=8A=B8=EB=9E=9C=EC=9E=AD?= =?UTF-8?q?=EC=85=98=20=EC=A0=9C=EA=B1=B0=20=EB=B0=8F=20fileUrls=EB=A5=BC?= =?UTF-8?q?=20=EB=B0=9B=EC=A7=80=20=EC=95=8A=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weeth/domain/board/domain/service/PostUpdateService.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/leets/weeth/domain/board/domain/service/PostUpdateService.java b/src/main/java/leets/weeth/domain/board/domain/service/PostUpdateService.java index a7406814..159d7722 100644 --- a/src/main/java/leets/weeth/domain/board/domain/service/PostUpdateService.java +++ b/src/main/java/leets/weeth/domain/board/domain/service/PostUpdateService.java @@ -15,9 +15,8 @@ @RequiredArgsConstructor public class PostUpdateService { - @Transactional - public void update(Post post, PostDTO.Update dto, List fileUrls){ - post.update(dto, fileUrls); + public void update(Post post, PostDTO.Update dto){ + post.update(dto); } } From 627faf452a456c9700676cae495b3869f0721d72 Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sat, 16 Nov 2024 19:31:50 +0900 Subject: [PATCH 08/41] =?UTF-8?q?refactor:=20=ED=8A=B8=EB=9E=9C=EC=9E=AD?= =?UTF-8?q?=EC=85=98=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weeth/domain/board/domain/service/PostDeleteService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/leets/weeth/domain/board/domain/service/PostDeleteService.java b/src/main/java/leets/weeth/domain/board/domain/service/PostDeleteService.java index d30f74e3..5af7aa2c 100644 --- a/src/main/java/leets/weeth/domain/board/domain/service/PostDeleteService.java +++ b/src/main/java/leets/weeth/domain/board/domain/service/PostDeleteService.java @@ -11,7 +11,6 @@ public class PostDeleteService { private final PostRepository postRepository; - @Transactional public void delete(Long postId) { postRepository.deleteById(postId); } From 3d93b2f71ee8fadcff872afc35d795d84fd05967 Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sat, 16 Nov 2024 19:41:48 +0900 Subject: [PATCH 09/41] =?UTF-8?q?refactor:=20=EA=B2=8C=EC=8B=9C=EA=B8=80?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1,=20=EC=88=98=EC=A0=95=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/usecase/PostUseCaseImpl.java | 58 +++++++++++++------ .../application/usecase/PostUsecase.java | 4 +- 2 files changed, 43 insertions(+), 19 deletions(-) diff --git a/src/main/java/leets/weeth/domain/board/application/usecase/PostUseCaseImpl.java b/src/main/java/leets/weeth/domain/board/application/usecase/PostUseCaseImpl.java index dd7da129..44b3928c 100644 --- a/src/main/java/leets/weeth/domain/board/application/usecase/PostUseCaseImpl.java +++ b/src/main/java/leets/weeth/domain/board/application/usecase/PostUseCaseImpl.java @@ -1,22 +1,27 @@ package leets.weeth.domain.board.application.usecase; import leets.weeth.domain.board.application.dto.PostDTO; +import leets.weeth.domain.board.application.exception.PostNotFoundException; import leets.weeth.domain.board.application.mapper.PostMapper; import leets.weeth.domain.board.domain.entity.Post; import leets.weeth.domain.board.domain.service.PostDeleteService; import leets.weeth.domain.board.domain.service.PostFindService; import leets.weeth.domain.board.domain.service.PostSaveService; import leets.weeth.domain.board.domain.service.PostUpdateService; -import leets.weeth.domain.file.service.S3Service; +import leets.weeth.domain.file.application.dto.request.FileUpdateRequest; +import leets.weeth.domain.file.application.mapper.FileMapper; +import leets.weeth.domain.file.domain.entity.File; +import leets.weeth.domain.file.domain.service.FileGetService; +import leets.weeth.domain.file.domain.service.FileSaveService; +import leets.weeth.domain.file.domain.service.FileUpdateService; +import leets.weeth.domain.user.application.exception.UserNotMatchException; import leets.weeth.domain.user.domain.entity.User; import leets.weeth.domain.user.domain.service.UserGetService; -import leets.weeth.domain.board.application.exception.PostNotFoundException; -import leets.weeth.domain.user.application.exception.UserNotMatchException; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; -import org.springframework.web.multipart.MultipartFile; +import org.springframework.transaction.annotation.Transactional; import java.util.List; @@ -30,17 +35,26 @@ public class PostUseCaseImpl implements PostUsecase { private final PostDeleteService postDeleteService; private final UserGetService userGetService; - private final S3Service s3Service; + private final FileSaveService fileSaveService; + private final FileGetService fileGetService; + private final FileUpdateService fileUpdateService; private final PostMapper mapper; + private final FileMapper fileMapper; @Override - public void save(PostDTO.Save request, List files, Long userId) { + @Transactional + public void save(PostDTO.Save request, Long userId) { User user = userGetService.find(userId); - List fileUrls; - fileUrls = s3Service.uploadFiles(files); - postSaveService.save(mapper.fromPostDto(request, fileUrls, user)); + Post post = mapper.fromPostDto(request, user); + postSaveService.save(post); + + List files = request.files().stream() + .map(fileSaveRequest -> fileMapper.toFile(fileSaveRequest.fileName(), fileSaveRequest.fileUrl(), post)) + .toList(); + + fileSaveService.save(files); } @Override @@ -55,12 +69,12 @@ public List findPosts(Long postId, Integer count) { Long finalPostId = postFindService.findFinalPostId(); // 첫번째 요청인 경우 - if(postId==null){ + if (postId == null) { postId = finalPostId + 1; } // postId가 1 이하이거나 최대값보다 클경우 - if(postId < 1 || postId > finalPostId + 1){ + if (postId < 1 || postId > finalPostId + 1) { throw new PostNotFoundException(); } @@ -74,27 +88,37 @@ public List findPosts(Long postId, Integer count) { } @Override - public void update(Long postId, PostDTO.Update dto, List files, Long userId) throws UserNotMatchException { + @Transactional + public void update(Long postId, PostDTO.Update dto, Long userId) throws UserNotMatchException { Post post = validateOwner(postId, userId); - List fileUrls = post.getFileUrls(); - List uploadedFileUrls = s3Service.uploadFiles(files); + List fileList = fileGetService.findAllByPost(postId); - fileUrls.addAll(uploadedFileUrls); + updateFiles(fileList, dto.files()); - postUpdateService.update(post, dto, fileUrls); + postUpdateService.update(post, dto); } @Override + @Transactional public void delete(Long postId, Long userId) throws UserNotMatchException { validateOwner(postId, userId); postDeleteService.delete(postId); } + private void updateFiles(List fileList, List dto) { + for (File file : fileList) { + dto.stream() + .filter(updateRequest -> updateRequest.fileId().equals(file.getId())) + .findFirst() + .ifPresent(updateRequest -> fileUpdateService.update(file, updateRequest)); + } + } + private Post validateOwner(Long postId, Long userId) throws UserNotMatchException { Post post = postFindService.find(postId); - if (!post.getUser().getId().equals(userId)) { + if (post.getUser().getId().equals(userId)) { throw new UserNotMatchException(); } return post; diff --git a/src/main/java/leets/weeth/domain/board/application/usecase/PostUsecase.java b/src/main/java/leets/weeth/domain/board/application/usecase/PostUsecase.java index 30bbf762..4cd55926 100644 --- a/src/main/java/leets/weeth/domain/board/application/usecase/PostUsecase.java +++ b/src/main/java/leets/weeth/domain/board/application/usecase/PostUsecase.java @@ -8,13 +8,13 @@ public interface PostUsecase { - void save(PostDTO.Save request, List files, Long userId); + void save(PostDTO.Save request, Long userId); PostDTO.Response findPost(Long postId); List findPosts(Long postId, Integer count); - void update(Long postId, PostDTO.Update dto, List files, Long userId) throws UserNotMatchException; + void update(Long postId, PostDTO.Update dto, Long userId) throws UserNotMatchException; void delete(Long postId, Long userId) throws UserNotMatchException; From 1007d7118333034ad504d8c219fd06f47c0b6d49 Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sat, 16 Nov 2024 19:43:45 +0900 Subject: [PATCH 10/41] =?UTF-8?q?refactor:=20file=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?=EC=B1=85=EC=9E=84=EC=9D=84=20=EC=9D=B4=EC=A0=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../board/application/usecase/PostUseCaseImpl.java | 11 +---------- .../domain/file/domain/service/FileUpdateService.java | 11 +++++++++++ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/java/leets/weeth/domain/board/application/usecase/PostUseCaseImpl.java b/src/main/java/leets/weeth/domain/board/application/usecase/PostUseCaseImpl.java index 44b3928c..c4e02751 100644 --- a/src/main/java/leets/weeth/domain/board/application/usecase/PostUseCaseImpl.java +++ b/src/main/java/leets/weeth/domain/board/application/usecase/PostUseCaseImpl.java @@ -94,7 +94,7 @@ public void update(Long postId, PostDTO.Update dto, Long userId) throws UserNotM List fileList = fileGetService.findAllByPost(postId); - updateFiles(fileList, dto.files()); + fileUpdateService.updateFiles(fileList, dto.files()); postUpdateService.update(post, dto); } @@ -106,15 +106,6 @@ public void delete(Long postId, Long userId) throws UserNotMatchException { postDeleteService.delete(postId); } - private void updateFiles(List fileList, List dto) { - for (File file : fileList) { - dto.stream() - .filter(updateRequest -> updateRequest.fileId().equals(file.getId())) - .findFirst() - .ifPresent(updateRequest -> fileUpdateService.update(file, updateRequest)); - } - } - private Post validateOwner(Long postId, Long userId) throws UserNotMatchException { Post post = postFindService.find(postId); diff --git a/src/main/java/leets/weeth/domain/file/domain/service/FileUpdateService.java b/src/main/java/leets/weeth/domain/file/domain/service/FileUpdateService.java index ea795e2e..d84bea4c 100644 --- a/src/main/java/leets/weeth/domain/file/domain/service/FileUpdateService.java +++ b/src/main/java/leets/weeth/domain/file/domain/service/FileUpdateService.java @@ -5,6 +5,8 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.util.List; + @Service @RequiredArgsConstructor public class FileUpdateService { @@ -12,4 +14,13 @@ public class FileUpdateService { public void update(File file, FileUpdateRequest dto) { file.update(dto.fileName(), dto.fileUrl()); } + + public void updateFiles(List fileList, List dto) { + for (File file : fileList) { + dto.stream() + .filter(updateRequest -> updateRequest.fileId().equals(file.getId())) + .findFirst() + .ifPresent(updateRequest -> file.update(updateRequest.fileName(), updateRequest.fileUrl())); + } + } } From cd7aac18dd11dcf9e32d59e43714a546c6af1c63 Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sat, 16 Nov 2024 19:45:42 +0900 Subject: [PATCH 11/41] =?UTF-8?q?refactor:=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EB=8D=98=EC=A7=80=EA=B8=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/board/application/usecase/PostUseCaseImpl.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/leets/weeth/domain/board/application/usecase/PostUseCaseImpl.java b/src/main/java/leets/weeth/domain/board/application/usecase/PostUseCaseImpl.java index c4e02751..1ca64a52 100644 --- a/src/main/java/leets/weeth/domain/board/application/usecase/PostUseCaseImpl.java +++ b/src/main/java/leets/weeth/domain/board/application/usecase/PostUseCaseImpl.java @@ -89,7 +89,7 @@ public List findPosts(Long postId, Integer count) { @Override @Transactional - public void update(Long postId, PostDTO.Update dto, Long userId) throws UserNotMatchException { + public void update(Long postId, PostDTO.Update dto, Long userId) { Post post = validateOwner(postId, userId); List fileList = fileGetService.findAllByPost(postId); @@ -101,12 +101,12 @@ public void update(Long postId, PostDTO.Update dto, Long userId) throws UserNotM @Override @Transactional - public void delete(Long postId, Long userId) throws UserNotMatchException { + public void delete(Long postId, Long userId) { validateOwner(postId, userId); postDeleteService.delete(postId); } - private Post validateOwner(Long postId, Long userId) throws UserNotMatchException { + private Post validateOwner(Long postId, Long userId) { Post post = postFindService.find(postId); if (post.getUser().getId().equals(userId)) { From a97b8ce4d04c3edf3096c34d97f041e57bc6631d Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sat, 16 Nov 2024 19:53:59 +0900 Subject: [PATCH 12/41] =?UTF-8?q?refactor:=20file=EC=9D=84=20postId?= =?UTF-8?q?=EB=A1=9C=20=EA=B0=80=EC=A0=B8=EC=98=A4=EB=8D=98=20=EA=B2=83=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../leets/weeth/domain/file/domain/service/FileGetService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/leets/weeth/domain/file/domain/service/FileGetService.java b/src/main/java/leets/weeth/domain/file/domain/service/FileGetService.java index 68200c67..77ce1d24 100644 --- a/src/main/java/leets/weeth/domain/file/domain/service/FileGetService.java +++ b/src/main/java/leets/weeth/domain/file/domain/service/FileGetService.java @@ -18,6 +18,6 @@ public List findAllByPost(Long postId) { } public List findAllByNotice(Long noticeId) { - return fileRepository.findAllByPostId(noticeId); + return fileRepository.findAllByNoticeId(noticeId); } } From b6f1ce35f27bff0d956e7c4e6e38dfd58869ee09 Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sat, 16 Nov 2024 19:54:20 +0900 Subject: [PATCH 13/41] =?UTF-8?q?refactor:=20=ED=8A=B8=EB=9E=9C=EC=9E=AD?= =?UTF-8?q?=EC=85=98=20=EC=83=81=EC=9C=84=EB=A1=9C=20=EC=9D=B4=EC=A0=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weeth/domain/board/domain/service/NoticeSaveService.java | 1 - .../domain/board/domain/service/NoticeUpdateService.java | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/leets/weeth/domain/board/domain/service/NoticeSaveService.java b/src/main/java/leets/weeth/domain/board/domain/service/NoticeSaveService.java index e5454869..b26e1061 100644 --- a/src/main/java/leets/weeth/domain/board/domain/service/NoticeSaveService.java +++ b/src/main/java/leets/weeth/domain/board/domain/service/NoticeSaveService.java @@ -12,7 +12,6 @@ public class NoticeSaveService { private final NoticeRepository noticeRepository; - @Transactional public void save(Notice notice){ noticeRepository.save(notice); } diff --git a/src/main/java/leets/weeth/domain/board/domain/service/NoticeUpdateService.java b/src/main/java/leets/weeth/domain/board/domain/service/NoticeUpdateService.java index 69878d2a..c5197d11 100644 --- a/src/main/java/leets/weeth/domain/board/domain/service/NoticeUpdateService.java +++ b/src/main/java/leets/weeth/domain/board/domain/service/NoticeUpdateService.java @@ -12,9 +12,8 @@ @RequiredArgsConstructor public class NoticeUpdateService { - @Transactional - public void update(Notice notice, NoticeDTO.Update dto, List fileUrls){ - notice.update(dto, fileUrls); + public void update(Notice notice, NoticeDTO.Update dto){ + notice.update(dto); } } From afe72cae4e912db49adf164fee041a2539c0b12a Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sat, 16 Nov 2024 19:54:51 +0900 Subject: [PATCH 14/41] =?UTF-8?q?refactor:=20=EA=B3=B5=EC=A7=80=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1,=20=EC=88=98=EC=A0=95=20=EB=A1=9C=EC=A7=81?= =?UTF-8?q?=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/usecase/NoticeUsecase.java | 4 +- .../usecase/NoticeUsecaseImpl.java | 46 ++++++++++++------- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/main/java/leets/weeth/domain/board/application/usecase/NoticeUsecase.java b/src/main/java/leets/weeth/domain/board/application/usecase/NoticeUsecase.java index 4c98526e..b0db4d6f 100644 --- a/src/main/java/leets/weeth/domain/board/application/usecase/NoticeUsecase.java +++ b/src/main/java/leets/weeth/domain/board/application/usecase/NoticeUsecase.java @@ -8,13 +8,13 @@ public interface NoticeUsecase { - void save(NoticeDTO.Save dto, List files, Long userId); + void save(NoticeDTO.Save dto, Long userId); NoticeDTO.Response findNotice(Long noticeId); List findNotices(Long noticeId, Integer count); - void update(Long noticeId, NoticeDTO.Update dto, List files, Long userId) throws UserNotMatchException; + void update(Long noticeId, NoticeDTO.Update dto, Long userId) throws UserNotMatchException; void delete(Long noticeId, Long userId) throws UserNotMatchException; diff --git a/src/main/java/leets/weeth/domain/board/application/usecase/NoticeUsecaseImpl.java b/src/main/java/leets/weeth/domain/board/application/usecase/NoticeUsecaseImpl.java index 6c5ed166..7b1c6ff8 100644 --- a/src/main/java/leets/weeth/domain/board/application/usecase/NoticeUsecaseImpl.java +++ b/src/main/java/leets/weeth/domain/board/application/usecase/NoticeUsecaseImpl.java @@ -1,22 +1,26 @@ package leets.weeth.domain.board.application.usecase; import leets.weeth.domain.board.application.dto.NoticeDTO; +import leets.weeth.domain.board.application.exception.NoticeNotFoundException; import leets.weeth.domain.board.application.mapper.NoticeMapper; import leets.weeth.domain.board.domain.entity.Notice; import leets.weeth.domain.board.domain.service.NoticeDeleteService; import leets.weeth.domain.board.domain.service.NoticeFindService; import leets.weeth.domain.board.domain.service.NoticeSaveService; import leets.weeth.domain.board.domain.service.NoticeUpdateService; -import leets.weeth.domain.file.service.S3Service; +import leets.weeth.domain.file.application.mapper.FileMapper; +import leets.weeth.domain.file.domain.entity.File; +import leets.weeth.domain.file.domain.service.FileGetService; +import leets.weeth.domain.file.domain.service.FileSaveService; +import leets.weeth.domain.file.domain.service.FileUpdateService; +import leets.weeth.domain.user.application.exception.UserNotMatchException; import leets.weeth.domain.user.domain.entity.User; import leets.weeth.domain.user.domain.service.UserGetService; -import leets.weeth.domain.board.application.exception.NoticeNotFoundException; -import leets.weeth.domain.user.application.exception.UserNotMatchException; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; -import org.springframework.web.multipart.MultipartFile; +import org.springframework.transaction.annotation.Transactional; import java.util.List; @@ -30,17 +34,26 @@ public class NoticeUsecaseImpl implements NoticeUsecase { private final NoticeDeleteService noticeDeleteService; private final UserGetService userGetService; - private final S3Service s3Service; + private final FileSaveService fileSaveService; + private final FileGetService fileGetService; + private final FileUpdateService fileUpdateService; private final NoticeMapper mapper; + private final FileMapper fileMapper; @Override - public void save(NoticeDTO.Save request, List files, Long userId) { + @Transactional + public void save(NoticeDTO.Save request, Long userId) { User user = userGetService.find(userId); - List fileUrls; - fileUrls = s3Service.uploadFiles(files); - noticeSaveService.save(mapper.fromNoticeDto(request, fileUrls, user)); + Notice notice = mapper.fromNoticeDto(request, user); + noticeSaveService.save(notice); + + List files = request.files().stream() + .map(fileSaveRequest -> fileMapper.toFile(fileSaveRequest.fileName(), fileSaveRequest.fileUrl(), notice)) + .toList(); + + fileSaveService.save(files); } @Override @@ -55,12 +68,12 @@ public List findNotices(Long noticeId, Integer count) { Long finalNoticeId = noticeFindService.findFinalNoticeId(); // 첫번째 요청인 경우 - if(noticeId==null){ + if (noticeId == null) { noticeId = finalNoticeId + 1; } // postId가 1 이하이거나 최대값보다 클경우 - if(noticeId < 1 || noticeId > finalNoticeId + 1){ + if (noticeId < 1 || noticeId > finalNoticeId + 1) { throw new NoticeNotFoundException(); } @@ -74,18 +87,19 @@ public List findNotices(Long noticeId, Integer count) { } @Override - public void update(Long noticeId, NoticeDTO.Update dto, List files, Long userId) throws UserNotMatchException { + @Transactional + public void update(Long noticeId, NoticeDTO.Update dto, Long userId) throws UserNotMatchException { Notice notice = validateOwner(noticeId, userId); - List fileUrls = notice.getFileUrls(); - List uploadedFileUrls = s3Service.uploadFiles(files); + List fileList = fileGetService.findAllByNotice(noticeId); - fileUrls.addAll(uploadedFileUrls); + fileUpdateService.updateFiles(fileList, dto.files()); - noticeUpdateService.update(notice, dto, fileUrls); + noticeUpdateService.update(notice, dto); } @Override + @Transactional public void delete(Long noticeId, Long userId) throws UserNotMatchException { validateOwner(noticeId, userId); noticeDeleteService.delete(noticeId); From e10c6b7b37e1dcb6fa0f90c8a2eb91e178635d17 Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sat, 16 Nov 2024 19:55:00 +0900 Subject: [PATCH 15/41] =?UTF-8?q?refactor:=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weeth/domain/board/application/usecase/PostUseCaseImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/leets/weeth/domain/board/application/usecase/PostUseCaseImpl.java b/src/main/java/leets/weeth/domain/board/application/usecase/PostUseCaseImpl.java index 1ca64a52..dae98035 100644 --- a/src/main/java/leets/weeth/domain/board/application/usecase/PostUseCaseImpl.java +++ b/src/main/java/leets/weeth/domain/board/application/usecase/PostUseCaseImpl.java @@ -109,7 +109,7 @@ public void delete(Long postId, Long userId) { private Post validateOwner(Long postId, Long userId) { Post post = postFindService.find(postId); - if (post.getUser().getId().equals(userId)) { + if (!post.getUser().getId().equals(userId)) { throw new UserNotMatchException(); } return post; From 5166121b80d79f70c877921355ca8377bbe75e20 Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sat, 16 Nov 2024 19:55:39 +0900 Subject: [PATCH 16/41] =?UTF-8?q?refactor:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EC=BB=AC=EB=9F=BC=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../leets/weeth/domain/board/domain/entity/Board.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/main/java/leets/weeth/domain/board/domain/entity/Board.java b/src/main/java/leets/weeth/domain/board/domain/entity/Board.java index 8c98ee93..9591ef24 100644 --- a/src/main/java/leets/weeth/domain/board/domain/entity/Board.java +++ b/src/main/java/leets/weeth/domain/board/domain/entity/Board.java @@ -38,9 +38,6 @@ public class Board extends BaseEntity { @JoinColumn(name = "user_id") private User user; - @Convert(converter = FileListConverter.class) - private List fileUrls = new ArrayList<>(); - private Integer commentCount; @PrePersist @@ -64,16 +61,14 @@ public void updateCommentCount(List comments) { .count(); } - public void updateUpperClass(NoticeDTO.Update dto, List fileUrls) { + public void updateUpperClass(NoticeDTO.Update dto) { this.title = dto.title(); this.content = dto.content(); - this.fileUrls = fileUrls; } - public void updateUpperClass(PostDTO.Update dto, List fileUrls) { + public void updateUpperClass(PostDTO.Update dto) { this.title = dto.title(); this.content = dto.content(); - this.fileUrls = fileUrls; } } From 67112e0c5ef8f25ab043219b4d5143fcdc53c4cb Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sat, 16 Nov 2024 20:26:12 +0900 Subject: [PATCH 17/41] =?UTF-8?q?feat:=20=EA=B3=B5=EC=A7=80=EC=82=AC?= =?UTF-8?q?=ED=95=AD=20=EC=83=81=EC=84=B8=20=EC=A1=B0=ED=9A=8C=20=EC=8B=9C?= =?UTF-8?q?=20file=20=EA=B4=80=EB=A0=A8=20=EC=A0=95=EB=B3=B4=EB=8F=84=20?= =?UTF-8?q?=ED=95=A8=EA=BB=98=20=EB=B0=98=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weeth/domain/board/application/dto/NoticeDTO.java | 5 +++-- .../domain/board/application/mapper/NoticeMapper.java | 8 +++++--- .../board/application/usecase/NoticeUsecaseImpl.java | 8 +++++++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/java/leets/weeth/domain/board/application/dto/NoticeDTO.java b/src/main/java/leets/weeth/domain/board/application/dto/NoticeDTO.java index 21cf1672..ca14c7fc 100644 --- a/src/main/java/leets/weeth/domain/board/application/dto/NoticeDTO.java +++ b/src/main/java/leets/weeth/domain/board/application/dto/NoticeDTO.java @@ -4,6 +4,7 @@ import leets.weeth.domain.comment.application.dto.CommentDTO; import leets.weeth.domain.file.application.dto.request.FileSaveRequest; import leets.weeth.domain.file.application.dto.request.FileUpdateRequest; +import leets.weeth.domain.file.application.dto.response.FileResponse; import lombok.Builder; import java.time.LocalDateTime; @@ -33,8 +34,8 @@ public record Response( String content, LocalDateTime time,//modifiedAt Integer commentCount, - List fileUrls, - List comments + List comments, + List files ){} @Builder diff --git a/src/main/java/leets/weeth/domain/board/application/mapper/NoticeMapper.java b/src/main/java/leets/weeth/domain/board/application/mapper/NoticeMapper.java index 34106305..05e8f564 100644 --- a/src/main/java/leets/weeth/domain/board/application/mapper/NoticeMapper.java +++ b/src/main/java/leets/weeth/domain/board/application/mapper/NoticeMapper.java @@ -5,6 +5,8 @@ import leets.weeth.domain.comment.application.dto.CommentDTO; import leets.weeth.domain.comment.application.mapper.CommentMapper; import leets.weeth.domain.comment.domain.entity.Comment; +import leets.weeth.domain.file.application.dto.response.FileResponse; +import leets.weeth.domain.file.domain.entity.File; import leets.weeth.domain.user.domain.entity.User; import org.mapstruct.*; @@ -28,11 +30,11 @@ public interface NoticeMapper { NoticeDTO.ResponseAll toAll(Notice notice); @Mappings({ - @Mapping(target = "name", source = "user.name"), + @Mapping(target = "name", source = "notice.user.name"), @Mapping(target = "comments", expression = "java(filterParentComments(notice.getComments()))"), - @Mapping(target = "time", source = "modifiedAt") + @Mapping(target = "time", source = "notice.modifiedAt") }) - NoticeDTO.Response toNoticeDto(Notice notice); + NoticeDTO.Response toNoticeDto(Notice notice, List files); default List filterParentComments(List comments) { if (comments == null || comments.isEmpty()) { diff --git a/src/main/java/leets/weeth/domain/board/application/usecase/NoticeUsecaseImpl.java b/src/main/java/leets/weeth/domain/board/application/usecase/NoticeUsecaseImpl.java index 7b1c6ff8..9b524a59 100644 --- a/src/main/java/leets/weeth/domain/board/application/usecase/NoticeUsecaseImpl.java +++ b/src/main/java/leets/weeth/domain/board/application/usecase/NoticeUsecaseImpl.java @@ -8,6 +8,7 @@ import leets.weeth.domain.board.domain.service.NoticeFindService; import leets.weeth.domain.board.domain.service.NoticeSaveService; import leets.weeth.domain.board.domain.service.NoticeUpdateService; +import leets.weeth.domain.file.application.dto.response.FileResponse; import leets.weeth.domain.file.application.mapper.FileMapper; import leets.weeth.domain.file.domain.entity.File; import leets.weeth.domain.file.domain.service.FileGetService; @@ -59,7 +60,12 @@ public void save(NoticeDTO.Save request, Long userId) { @Override public NoticeDTO.Response findNotice(Long noticeId) { Notice notice = noticeFindService.find(noticeId); - return mapper.toNoticeDto(notice); + + List response = fileGetService.findAllByNotice(noticeId).stream() + .map(fileMapper::toFileResponse) + .toList(); + + return mapper.toNoticeDto(notice, response); } @Override From d0e61ebd3182b8d99ee5cf8b88ad4bb5d3d391de Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sat, 16 Nov 2024 20:26:30 +0900 Subject: [PATCH 18/41] =?UTF-8?q?refactor:=20fileId=20=EC=88=98=EB=8F=99?= =?UTF-8?q?=20=EB=A7=A4=ED=95=91=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../leets/weeth/domain/file/application/mapper/FileMapper.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/leets/weeth/domain/file/application/mapper/FileMapper.java b/src/main/java/leets/weeth/domain/file/application/mapper/FileMapper.java index 1d856377..a4b47613 100644 --- a/src/main/java/leets/weeth/domain/file/application/mapper/FileMapper.java +++ b/src/main/java/leets/weeth/domain/file/application/mapper/FileMapper.java @@ -20,6 +20,7 @@ public interface FileMapper { @Mapping(target = "notice", source = "notice") File toFile(String fileName, String fileUrl, Notice notice); + @Mapping(target = "fileId", source = "file.id") FileResponse toFileResponse(File file); UrlResponse toUrlResponse(String fileName, String putUrl); From 725de7143badcf59a1f1a86e39c4999afb1053ef Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sat, 16 Nov 2024 20:26:50 +0900 Subject: [PATCH 19/41] =?UTF-8?q?feat:=20post=20=EC=83=81=EC=84=B8?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=EC=8B=9C=20file=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../leets/weeth/domain/board/application/dto/PostDTO.java | 5 +++-- .../weeth/domain/board/application/mapper/PostMapper.java | 7 ++++--- .../domain/board/application/usecase/PostUseCaseImpl.java | 8 +++++++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/java/leets/weeth/domain/board/application/dto/PostDTO.java b/src/main/java/leets/weeth/domain/board/application/dto/PostDTO.java index 4c0f1295..f86455f7 100644 --- a/src/main/java/leets/weeth/domain/board/application/dto/PostDTO.java +++ b/src/main/java/leets/weeth/domain/board/application/dto/PostDTO.java @@ -4,6 +4,7 @@ import leets.weeth.domain.comment.application.dto.CommentDTO; import leets.weeth.domain.file.application.dto.request.FileSaveRequest; import leets.weeth.domain.file.application.dto.request.FileUpdateRequest; +import leets.weeth.domain.file.application.dto.response.FileResponse; import lombok.Builder; import java.time.LocalDateTime; @@ -33,8 +34,8 @@ public record Response( String content, LocalDateTime time,//modifiedAt Integer commentCount, - List fileUrls, - List comments + List comments, + List files ){} @Builder diff --git a/src/main/java/leets/weeth/domain/board/application/mapper/PostMapper.java b/src/main/java/leets/weeth/domain/board/application/mapper/PostMapper.java index 78a5c251..dcb298dc 100644 --- a/src/main/java/leets/weeth/domain/board/application/mapper/PostMapper.java +++ b/src/main/java/leets/weeth/domain/board/application/mapper/PostMapper.java @@ -5,6 +5,7 @@ import leets.weeth.domain.comment.application.dto.CommentDTO; import leets.weeth.domain.comment.application.mapper.CommentMapper; import leets.weeth.domain.comment.domain.entity.Comment; +import leets.weeth.domain.file.application.dto.response.FileResponse; import leets.weeth.domain.user.domain.entity.User; import org.mapstruct.*; @@ -28,11 +29,11 @@ public interface PostMapper { PostDTO.ResponseAll toAll(Post post); @Mappings({ - @Mapping(target = "name", source = "user.name"), + @Mapping(target = "name", source = "post.user.name"), @Mapping(target = "comments", expression = "java(filterParentComments(post.getComments()))"), - @Mapping(target = "time", source = "modifiedAt") + @Mapping(target = "time", source = "post.modifiedAt") }) - PostDTO.Response toPostDto(Post post); + PostDTO.Response toPostDto(Post post, List files); default List filterParentComments(List comments) { if (comments == null || comments.isEmpty()) { diff --git a/src/main/java/leets/weeth/domain/board/application/usecase/PostUseCaseImpl.java b/src/main/java/leets/weeth/domain/board/application/usecase/PostUseCaseImpl.java index dae98035..043200b8 100644 --- a/src/main/java/leets/weeth/domain/board/application/usecase/PostUseCaseImpl.java +++ b/src/main/java/leets/weeth/domain/board/application/usecase/PostUseCaseImpl.java @@ -9,6 +9,7 @@ import leets.weeth.domain.board.domain.service.PostSaveService; import leets.weeth.domain.board.domain.service.PostUpdateService; import leets.weeth.domain.file.application.dto.request.FileUpdateRequest; +import leets.weeth.domain.file.application.dto.response.FileResponse; import leets.weeth.domain.file.application.mapper.FileMapper; import leets.weeth.domain.file.domain.entity.File; import leets.weeth.domain.file.domain.service.FileGetService; @@ -60,7 +61,12 @@ public void save(PostDTO.Save request, Long userId) { @Override public PostDTO.Response findPost(Long postId) { Post post = postFindService.find(postId); - return mapper.toPostDto(post); + + List response = fileGetService.findAllByPost(postId).stream() + .map(fileMapper::toFileResponse) + .toList(); + + return mapper.toPostDto(post, response); } @Override From 315c0caa8bd69feac4284568c4588679d3556897 Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sat, 16 Nov 2024 20:27:11 +0900 Subject: [PATCH 20/41] =?UTF-8?q?feat:=20=EC=8A=A4=EC=9B=A8=EA=B1=B0=20API?= =?UTF-8?q?=20=EC=9D=91=EB=8B=B5=20=EC=86=8D=EB=8F=84=20=EB=B0=98=ED=99=98?= =?UTF-8?q?=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 992865b4..c5f39637 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -15,6 +15,7 @@ springdoc: swagger-ui: operations-sorter: method tags-sorter: alpha + display-request-duration: true auth: kakao: From 9ed431bb7b0edf43b1123f29b4ae451a84f71b56 Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sat, 16 Nov 2024 20:32:54 +0900 Subject: [PATCH 21/41] =?UTF-8?q?feat:=20file=20delete=20service=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/service/FileDeleteService.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/main/java/leets/weeth/domain/file/domain/service/FileDeleteService.java diff --git a/src/main/java/leets/weeth/domain/file/domain/service/FileDeleteService.java b/src/main/java/leets/weeth/domain/file/domain/service/FileDeleteService.java new file mode 100644 index 00000000..eefde008 --- /dev/null +++ b/src/main/java/leets/weeth/domain/file/domain/service/FileDeleteService.java @@ -0,0 +1,23 @@ +package leets.weeth.domain.file.domain.service; + +import leets.weeth.domain.file.domain.entity.File; +import leets.weeth.domain.file.domain.repository.FileRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +@RequiredArgsConstructor +public class FileDeleteService { + + private final FileRepository fileRepository; + + public void delete(File file) { + fileRepository.delete(file); + } + + public void delete(List files) { + fileRepository.deleteAll(files); + } +} From fc7dfbf532895bbe1095d5c4a25a1c25e71d3e71 Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sat, 16 Nov 2024 20:33:06 +0900 Subject: [PATCH 22/41] =?UTF-8?q?feat:=20=EA=B3=B5=EC=A7=80=EC=82=AC?= =?UTF-8?q?=ED=95=AD,=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=20=EC=8B=9C=20file=EB=8F=84=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/usecase/NoticeUsecaseImpl.java | 15 +++++++++++++-- .../application/usecase/PostUseCaseImpl.java | 16 +++++++++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/main/java/leets/weeth/domain/board/application/usecase/NoticeUsecaseImpl.java b/src/main/java/leets/weeth/domain/board/application/usecase/NoticeUsecaseImpl.java index 9b524a59..59c8526c 100644 --- a/src/main/java/leets/weeth/domain/board/application/usecase/NoticeUsecaseImpl.java +++ b/src/main/java/leets/weeth/domain/board/application/usecase/NoticeUsecaseImpl.java @@ -11,6 +11,7 @@ import leets.weeth.domain.file.application.dto.response.FileResponse; import leets.weeth.domain.file.application.mapper.FileMapper; import leets.weeth.domain.file.domain.entity.File; +import leets.weeth.domain.file.domain.service.FileDeleteService; import leets.weeth.domain.file.domain.service.FileGetService; import leets.weeth.domain.file.domain.service.FileSaveService; import leets.weeth.domain.file.domain.service.FileUpdateService; @@ -35,9 +36,11 @@ public class NoticeUsecaseImpl implements NoticeUsecase { private final NoticeDeleteService noticeDeleteService; private final UserGetService userGetService; + private final FileSaveService fileSaveService; private final FileGetService fileGetService; private final FileUpdateService fileUpdateService; + private final FileDeleteService fileDeleteService; private final NoticeMapper mapper; private final FileMapper fileMapper; @@ -61,7 +64,7 @@ public void save(NoticeDTO.Save request, Long userId) { public NoticeDTO.Response findNotice(Long noticeId) { Notice notice = noticeFindService.find(noticeId); - List response = fileGetService.findAllByNotice(noticeId).stream() + List response = getFiles(noticeId).stream() .map(fileMapper::toFileResponse) .toList(); @@ -97,7 +100,7 @@ public List findNotices(Long noticeId, Integer count) { public void update(Long noticeId, NoticeDTO.Update dto, Long userId) throws UserNotMatchException { Notice notice = validateOwner(noticeId, userId); - List fileList = fileGetService.findAllByNotice(noticeId); + List fileList = getFiles(noticeId); fileUpdateService.updateFiles(fileList, dto.files()); @@ -108,9 +111,17 @@ public void update(Long noticeId, NoticeDTO.Update dto, Long userId) throws User @Transactional public void delete(Long noticeId, Long userId) throws UserNotMatchException { validateOwner(noticeId, userId); + + List fileList = getFiles(noticeId); + fileDeleteService.delete(fileList); + noticeDeleteService.delete(noticeId); } + private List getFiles(Long noticeId) { + return fileGetService.findAllByNotice(noticeId); + } + private Notice validateOwner(Long noticeId, Long userId) throws UserNotMatchException { Notice notice = noticeFindService.find(noticeId); if (!notice.getUser().getId().equals(userId)) { diff --git a/src/main/java/leets/weeth/domain/board/application/usecase/PostUseCaseImpl.java b/src/main/java/leets/weeth/domain/board/application/usecase/PostUseCaseImpl.java index 043200b8..2fd6c022 100644 --- a/src/main/java/leets/weeth/domain/board/application/usecase/PostUseCaseImpl.java +++ b/src/main/java/leets/weeth/domain/board/application/usecase/PostUseCaseImpl.java @@ -8,10 +8,10 @@ import leets.weeth.domain.board.domain.service.PostFindService; import leets.weeth.domain.board.domain.service.PostSaveService; import leets.weeth.domain.board.domain.service.PostUpdateService; -import leets.weeth.domain.file.application.dto.request.FileUpdateRequest; import leets.weeth.domain.file.application.dto.response.FileResponse; import leets.weeth.domain.file.application.mapper.FileMapper; import leets.weeth.domain.file.domain.entity.File; +import leets.weeth.domain.file.domain.service.FileDeleteService; import leets.weeth.domain.file.domain.service.FileGetService; import leets.weeth.domain.file.domain.service.FileSaveService; import leets.weeth.domain.file.domain.service.FileUpdateService; @@ -36,9 +36,11 @@ public class PostUseCaseImpl implements PostUsecase { private final PostDeleteService postDeleteService; private final UserGetService userGetService; + private final FileSaveService fileSaveService; private final FileGetService fileGetService; private final FileUpdateService fileUpdateService; + private final FileDeleteService fileDeleteService; private final PostMapper mapper; private final FileMapper fileMapper; @@ -62,7 +64,7 @@ public void save(PostDTO.Save request, Long userId) { public PostDTO.Response findPost(Long postId) { Post post = postFindService.find(postId); - List response = fileGetService.findAllByPost(postId).stream() + List response = getFiles(postId).stream() .map(fileMapper::toFileResponse) .toList(); @@ -98,7 +100,7 @@ public List findPosts(Long postId, Integer count) { public void update(Long postId, PostDTO.Update dto, Long userId) { Post post = validateOwner(postId, userId); - List fileList = fileGetService.findAllByPost(postId); + List fileList = getFiles(postId); fileUpdateService.updateFiles(fileList, dto.files()); @@ -109,9 +111,17 @@ public void update(Long postId, PostDTO.Update dto, Long userId) { @Transactional public void delete(Long postId, Long userId) { validateOwner(postId, userId); + + List fileList = getFiles(postId); + fileDeleteService.delete(fileList); + postDeleteService.delete(postId); } + private List getFiles(Long postId) { + return fileGetService.findAllByPost(postId); + } + private Post validateOwner(Long postId, Long userId) { Post post = postFindService.find(postId); From 98a1d665627ddedc6b02a1ccd9067cd005495368 Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sat, 16 Nov 2024 20:33:38 +0900 Subject: [PATCH 23/41] =?UTF-8?q?refactor:=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EB=8D=98=EC=A7=80=EA=B8=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/board/application/usecase/NoticeUsecaseImpl.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/leets/weeth/domain/board/application/usecase/NoticeUsecaseImpl.java b/src/main/java/leets/weeth/domain/board/application/usecase/NoticeUsecaseImpl.java index 59c8526c..70f16df5 100644 --- a/src/main/java/leets/weeth/domain/board/application/usecase/NoticeUsecaseImpl.java +++ b/src/main/java/leets/weeth/domain/board/application/usecase/NoticeUsecaseImpl.java @@ -97,7 +97,7 @@ public List findNotices(Long noticeId, Integer count) { @Override @Transactional - public void update(Long noticeId, NoticeDTO.Update dto, Long userId) throws UserNotMatchException { + public void update(Long noticeId, NoticeDTO.Update dto, Long userId) { Notice notice = validateOwner(noticeId, userId); List fileList = getFiles(noticeId); @@ -109,7 +109,7 @@ public void update(Long noticeId, NoticeDTO.Update dto, Long userId) throws User @Override @Transactional - public void delete(Long noticeId, Long userId) throws UserNotMatchException { + public void delete(Long noticeId, Long userId) { validateOwner(noticeId, userId); List fileList = getFiles(noticeId); @@ -122,7 +122,7 @@ private List getFiles(Long noticeId) { return fileGetService.findAllByNotice(noticeId); } - private Notice validateOwner(Long noticeId, Long userId) throws UserNotMatchException { + private Notice validateOwner(Long noticeId, Long userId) { Notice notice = noticeFindService.find(noticeId); if (!notice.getUser().getId().equals(userId)) { throw new UserNotMatchException(); From 6c14dadc3bbc97e003d64b5671e7934f6f8a6bc5 Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sun, 17 Nov 2024 17:45:56 +0900 Subject: [PATCH 24/41] =?UTF-8?q?feat:=20File=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=20=EC=8B=9C=20=EC=9C=A0=ED=9A=A8=EC=84=B1=20?= =?UTF-8?q?=EA=B2=80=EC=A6=9D=20=EC=98=B5=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../file/application/dto/request/FileSaveRequest.java | 7 +++++-- .../file/application/dto/request/FileUpdateRequest.java | 5 +++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/leets/weeth/domain/file/application/dto/request/FileSaveRequest.java b/src/main/java/leets/weeth/domain/file/application/dto/request/FileSaveRequest.java index 8965f7a4..4d705c6f 100644 --- a/src/main/java/leets/weeth/domain/file/application/dto/request/FileSaveRequest.java +++ b/src/main/java/leets/weeth/domain/file/application/dto/request/FileSaveRequest.java @@ -1,7 +1,10 @@ package leets.weeth.domain.file.application.dto.request; +import jakarta.validation.constraints.NotBlank; +import org.hibernate.validator.constraints.URL; + public record FileSaveRequest( - String fileName, - String fileUrl + @NotBlank String fileName, + @URL String fileUrl ) { } diff --git a/src/main/java/leets/weeth/domain/file/application/dto/request/FileUpdateRequest.java b/src/main/java/leets/weeth/domain/file/application/dto/request/FileUpdateRequest.java index 8285a646..ee024ef5 100644 --- a/src/main/java/leets/weeth/domain/file/application/dto/request/FileUpdateRequest.java +++ b/src/main/java/leets/weeth/domain/file/application/dto/request/FileUpdateRequest.java @@ -1,10 +1,11 @@ package leets.weeth.domain.file.application.dto.request; import jakarta.validation.constraints.NotBlank; +import org.hibernate.validator.constraints.URL; public record FileUpdateRequest( @NotBlank Long fileId, - String fileName, - String fileUrl + @NotBlank String fileName, + @URL String fileUrl ) { } From 050c7566011b6ddafb448e91f4c598b2e2192469 Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sun, 17 Nov 2024 17:46:12 +0900 Subject: [PATCH 25/41] =?UTF-8?q?feat:=20File=EC=97=90=20=EC=98=81?= =?UTF-8?q?=EC=88=98=EC=A6=9D=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/leets/weeth/domain/file/domain/entity/File.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/leets/weeth/domain/file/domain/entity/File.java b/src/main/java/leets/weeth/domain/file/domain/entity/File.java index 60ebc533..21faf750 100644 --- a/src/main/java/leets/weeth/domain/file/domain/entity/File.java +++ b/src/main/java/leets/weeth/domain/file/domain/entity/File.java @@ -1,6 +1,7 @@ package leets.weeth.domain.file.domain.entity; import jakarta.persistence.*; +import leets.weeth.domain.account.domain.entity.Receipt; import leets.weeth.domain.board.domain.entity.Notice; import leets.weeth.domain.board.domain.entity.Post; import lombok.*; @@ -14,7 +15,7 @@ public class File { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - public Long id; + private Long id; private String fileName; @@ -28,6 +29,10 @@ public class File { @JoinColumn(name = "notice_id") private Notice notice; + @ManyToOne + @JoinColumn(name = "receipt_id") + private Receipt receipt; + public void update(String fileName, String fileUrl) { this.fileName = fileName; this.fileUrl = fileUrl; From da1e53f0f77bb53162377ab54416bf951ed20035 Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sun, 17 Nov 2024 17:46:31 +0900 Subject: [PATCH 26/41] =?UTF-8?q?feat:=20=EC=98=81=EC=88=98=EC=A6=9D=20id?= =?UTF-8?q?=EB=A1=9C=20file=EC=9D=84=20=EA=B0=80=EC=A0=B8=EC=98=A4?= =?UTF-8?q?=EB=8A=94=20=EB=AA=85=EB=A0=B9=EC=96=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weeth/domain/file/domain/repository/FileRepository.java | 2 ++ .../weeth/domain/file/domain/service/FileGetService.java | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/main/java/leets/weeth/domain/file/domain/repository/FileRepository.java b/src/main/java/leets/weeth/domain/file/domain/repository/FileRepository.java index de102c43..2daee101 100644 --- a/src/main/java/leets/weeth/domain/file/domain/repository/FileRepository.java +++ b/src/main/java/leets/weeth/domain/file/domain/repository/FileRepository.java @@ -10,4 +10,6 @@ public interface FileRepository extends JpaRepository { List findAllByPostId(Long postId); List findAllByNoticeId(Long noticeId); + + List findAllByReceiptId(Long receiptId); } diff --git a/src/main/java/leets/weeth/domain/file/domain/service/FileGetService.java b/src/main/java/leets/weeth/domain/file/domain/service/FileGetService.java index 77ce1d24..cfeb82f0 100644 --- a/src/main/java/leets/weeth/domain/file/domain/service/FileGetService.java +++ b/src/main/java/leets/weeth/domain/file/domain/service/FileGetService.java @@ -20,4 +20,8 @@ public List findAllByPost(Long postId) { public List findAllByNotice(Long noticeId) { return fileRepository.findAllByNoticeId(noticeId); } + + public List findAllByReceipt(Long receiptId) { + return fileRepository.findAllByReceiptId(receiptId); + } } From 27aaa886242df22bfd2f7e4812ed316d12f83d1e Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sun, 17 Nov 2024 17:47:56 +0900 Subject: [PATCH 27/41] =?UTF-8?q?feat:=20=ED=8C=8C=EC=9D=BC=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=EC=98=B5=EC=85=98=EC=97=90=20=EC=9C=A0=ED=9A=A8?= =?UTF-8?q?=EC=84=B1=20=EA=B2=80=EC=A6=9D=20=EC=98=B5=EC=85=98=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../account/application/dto/ReceiptDTO.java | 8 ++++++-- .../domain/board/application/dto/NoticeDTO.java | 17 +++++++++++------ .../domain/board/application/dto/PostDTO.java | 5 +++-- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/main/java/leets/weeth/domain/account/application/dto/ReceiptDTO.java b/src/main/java/leets/weeth/domain/account/application/dto/ReceiptDTO.java index d5fe0679..03004b90 100644 --- a/src/main/java/leets/weeth/domain/account/application/dto/ReceiptDTO.java +++ b/src/main/java/leets/weeth/domain/account/application/dto/ReceiptDTO.java @@ -1,6 +1,9 @@ package leets.weeth.domain.account.application.dto; +import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; +import leets.weeth.domain.file.application.dto.request.FileSaveRequest; +import leets.weeth.domain.file.application.dto.response.FileResponse; import java.time.LocalDate; import java.util.List; @@ -12,13 +15,14 @@ public record Response( String description, Integer amount, LocalDate date, - List images + List files ) {} public record Save( String description, @NotNull Integer amount, @NotNull LocalDate date, - @NotNull Integer cardinal + @NotNull Integer cardinal, + @Valid List<@NotNull FileSaveRequest> files ) {} } diff --git a/src/main/java/leets/weeth/domain/board/application/dto/NoticeDTO.java b/src/main/java/leets/weeth/domain/board/application/dto/NoticeDTO.java index ca14c7fc..a677113a 100644 --- a/src/main/java/leets/weeth/domain/board/application/dto/NoticeDTO.java +++ b/src/main/java/leets/weeth/domain/board/application/dto/NoticeDTO.java @@ -1,5 +1,6 @@ package leets.weeth.domain.board.application.dto; +import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; import leets.weeth.domain.comment.application.dto.CommentDTO; import leets.weeth.domain.file.application.dto.request.FileSaveRequest; @@ -16,15 +17,17 @@ public class NoticeDTO { public record Save( @NotNull String title, @NotNull String content, - List files - ){} + @Valid List<@NotNull FileUpdateRequest> files + ) { + } @Builder public record Update( @NotNull String title, @NotNull String content, - List files - ){} + @Valid List<@NotNull FileUpdateRequest> files + ) { + } @Builder public record Response( @@ -36,7 +39,8 @@ public record Response( Integer commentCount, List comments, List files - ){} + ) { + } @Builder public record ResponseAll( @@ -46,6 +50,7 @@ public record ResponseAll( String content, LocalDateTime time,//modifiedAt Integer commentCount - ){} + ) { + } } diff --git a/src/main/java/leets/weeth/domain/board/application/dto/PostDTO.java b/src/main/java/leets/weeth/domain/board/application/dto/PostDTO.java index f86455f7..62c8ff2b 100644 --- a/src/main/java/leets/weeth/domain/board/application/dto/PostDTO.java +++ b/src/main/java/leets/weeth/domain/board/application/dto/PostDTO.java @@ -1,5 +1,6 @@ package leets.weeth.domain.board.application.dto; +import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; import leets.weeth.domain.comment.application.dto.CommentDTO; import leets.weeth.domain.file.application.dto.request.FileSaveRequest; @@ -16,14 +17,14 @@ public class PostDTO { public record Save( @NotNull String title, @NotNull String content, - List files + @Valid List<@NotNull FileSaveRequest> files ){} @Builder public record Update( @NotNull String title, @NotNull String content, - List files + @Valid List<@NotNull FileUpdateRequest> files ){} @Builder From 7b256c8e311c5ac0e5c2017f0d5d98e4a91d1d6f Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sun, 17 Nov 2024 17:51:17 +0900 Subject: [PATCH 28/41] =?UTF-8?q?refactor:=20dto=EB=AA=85=20=EC=98=A4?= =?UTF-8?q?=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../leets/weeth/domain/board/application/dto/NoticeDTO.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/leets/weeth/domain/board/application/dto/NoticeDTO.java b/src/main/java/leets/weeth/domain/board/application/dto/NoticeDTO.java index a677113a..66043a37 100644 --- a/src/main/java/leets/weeth/domain/board/application/dto/NoticeDTO.java +++ b/src/main/java/leets/weeth/domain/board/application/dto/NoticeDTO.java @@ -17,7 +17,7 @@ public class NoticeDTO { public record Save( @NotNull String title, @NotNull String content, - @Valid List<@NotNull FileUpdateRequest> files + @Valid List<@NotNull FileSaveRequest> files ) { } From eab4ef5ee84e37bc4d76c4c59a1ef41a0e9bfeca Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sun, 17 Nov 2024 17:51:43 +0900 Subject: [PATCH 29/41] =?UTF-8?q?feat:=20=ED=8C=8C=EC=9D=BC=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=EC=8B=9C=20File=20=EA=B0=9D=EC=B2=B4=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=EC=B1=85=EC=9E=84=EC=9D=84=20mapper=EB=A1=9C=20?= =?UTF-8?q?=EC=9D=B4=EC=A0=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../file/application/mapper/FileMapper.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/main/java/leets/weeth/domain/file/application/mapper/FileMapper.java b/src/main/java/leets/weeth/domain/file/application/mapper/FileMapper.java index a4b47613..c5ab0379 100644 --- a/src/main/java/leets/weeth/domain/file/application/mapper/FileMapper.java +++ b/src/main/java/leets/weeth/domain/file/application/mapper/FileMapper.java @@ -1,8 +1,10 @@ package leets.weeth.domain.file.application.mapper; +import leets.weeth.domain.account.domain.entity.Receipt; import leets.weeth.domain.board.domain.entity.Notice; import leets.weeth.domain.board.domain.entity.Post; import leets.weeth.domain.comment.application.mapper.CommentMapper; +import leets.weeth.domain.file.application.dto.request.FileSaveRequest; import leets.weeth.domain.file.application.dto.response.FileResponse; import leets.weeth.domain.file.application.dto.response.UrlResponse; import leets.weeth.domain.file.domain.entity.File; @@ -11,6 +13,10 @@ import org.mapstruct.MappingConstants; import org.mapstruct.ReportingPolicy; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + @Mapper(componentModel = MappingConstants.ComponentModel.SPRING, uses = CommentMapper.class, unmappedTargetPolicy = ReportingPolicy.IGNORE) public interface FileMapper { @@ -20,8 +26,42 @@ public interface FileMapper { @Mapping(target = "notice", source = "notice") File toFile(String fileName, String fileUrl, Notice notice); + @Mapping(target = "receipt", source = "receipt") + File toFile(String fileName, String fileUrl, Receipt receipt); + @Mapping(target = "fileId", source = "file.id") FileResponse toFileResponse(File file); UrlResponse toUrlResponse(String fileName, String putUrl); + + default List toFileList(List requests, Post post) { + List dto = requests; + if (dto == null || dto.isEmpty()) { + return Collections.emptyList(); + } + + return dto.stream() + .map(request -> toFile(request.fileName(), request.fileUrl(), post)) + .collect(Collectors.toList()); + } + + default List toFileList(List requests, Notice notice) { + if (requests == null || requests.isEmpty()) { + return Collections.emptyList(); + } + + return requests.stream() + .map(request -> toFile(request.fileName(), request.fileUrl(), notice)) + .collect(Collectors.toList()); + } + + default List toFileList(List requests, Receipt receipt) { + if (requests == null || requests.isEmpty()) { + return Collections.emptyList(); + } + + return requests.stream() + .map(request -> toFile(request.fileName(), request.fileUrl(), receipt)) + .collect(Collectors.toList()); + } } From ab1e91820dc284589a0de9bf699def207f3f55ec Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sun, 17 Nov 2024 17:52:01 +0900 Subject: [PATCH 30/41] =?UTF-8?q?refactor:=20=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5=EC=8B=9C=20File=20=EA=B0=9D=EC=B2=B4=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20=EC=B1=85=EC=9E=84=EC=9D=84=20mapper?= =?UTF-8?q?=EB=A1=9C=20=EC=9D=B4=EC=A0=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/board/application/usecase/NoticeUsecaseImpl.java | 5 +---- .../domain/board/application/usecase/PostUseCaseImpl.java | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/main/java/leets/weeth/domain/board/application/usecase/NoticeUsecaseImpl.java b/src/main/java/leets/weeth/domain/board/application/usecase/NoticeUsecaseImpl.java index 70f16df5..687b8189 100644 --- a/src/main/java/leets/weeth/domain/board/application/usecase/NoticeUsecaseImpl.java +++ b/src/main/java/leets/weeth/domain/board/application/usecase/NoticeUsecaseImpl.java @@ -53,10 +53,7 @@ public void save(NoticeDTO.Save request, Long userId) { Notice notice = mapper.fromNoticeDto(request, user); noticeSaveService.save(notice); - List files = request.files().stream() - .map(fileSaveRequest -> fileMapper.toFile(fileSaveRequest.fileName(), fileSaveRequest.fileUrl(), notice)) - .toList(); - + List files = fileMapper.toFileList(request.files(), notice); fileSaveService.save(files); } diff --git a/src/main/java/leets/weeth/domain/board/application/usecase/PostUseCaseImpl.java b/src/main/java/leets/weeth/domain/board/application/usecase/PostUseCaseImpl.java index 2fd6c022..0da7dc3f 100644 --- a/src/main/java/leets/weeth/domain/board/application/usecase/PostUseCaseImpl.java +++ b/src/main/java/leets/weeth/domain/board/application/usecase/PostUseCaseImpl.java @@ -53,10 +53,7 @@ public void save(PostDTO.Save request, Long userId) { Post post = mapper.fromPostDto(request, user); postSaveService.save(post); - List files = request.files().stream() - .map(fileSaveRequest -> fileMapper.toFile(fileSaveRequest.fileName(), fileSaveRequest.fileUrl(), post)) - .toList(); - + List files = fileMapper.toFileList(request.files(), post); fileSaveService.save(files); } From 27559ea980346e2c4703bedab64365a85119e4a9 Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sun, 17 Nov 2024 17:52:25 +0900 Subject: [PATCH 31/41] =?UTF-8?q?refactor:=20=EC=98=81=EC=88=98=EC=A6=9D?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1,=20=EC=82=AD=EC=A0=9C=EC=8B=9C=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EA=B4=80=EB=A0=A8=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/mapper/ReceiptMapper.java | 5 ++- .../application/usecase/ReceiptUseCase.java | 2 +- .../usecase/ReceiptUseCaseImpl.java | 35 ++++++++++++++----- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/main/java/leets/weeth/domain/account/application/mapper/ReceiptMapper.java b/src/main/java/leets/weeth/domain/account/application/mapper/ReceiptMapper.java index ce76075b..725597b3 100644 --- a/src/main/java/leets/weeth/domain/account/application/mapper/ReceiptMapper.java +++ b/src/main/java/leets/weeth/domain/account/application/mapper/ReceiptMapper.java @@ -3,6 +3,7 @@ import leets.weeth.domain.account.application.dto.ReceiptDTO; import leets.weeth.domain.account.domain.entity.Account; import leets.weeth.domain.account.domain.entity.Receipt; +import leets.weeth.domain.file.application.dto.response.FileResponse; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.MappingConstants; @@ -15,8 +16,10 @@ public interface ReceiptMapper { List to(List account); + ReceiptDTO.Response to(Receipt receipt, List files); + @Mapping(target = "id", ignore = true) @Mapping(target = "description", source = "dto.description") @Mapping(target = "account", source = "account") - Receipt from(ReceiptDTO.Save dto, List images, Account account); + Receipt from(ReceiptDTO.Save dto, Account account); } diff --git a/src/main/java/leets/weeth/domain/account/application/usecase/ReceiptUseCase.java b/src/main/java/leets/weeth/domain/account/application/usecase/ReceiptUseCase.java index 430edf31..6207b941 100644 --- a/src/main/java/leets/weeth/domain/account/application/usecase/ReceiptUseCase.java +++ b/src/main/java/leets/weeth/domain/account/application/usecase/ReceiptUseCase.java @@ -6,7 +6,7 @@ import java.util.List; public interface ReceiptUseCase { - void save(ReceiptDTO.Save dto, List images); + void save(ReceiptDTO.Save dto); void delete(Long id); } diff --git a/src/main/java/leets/weeth/domain/account/application/usecase/ReceiptUseCaseImpl.java b/src/main/java/leets/weeth/domain/account/application/usecase/ReceiptUseCaseImpl.java index adc1d1d5..76e0dec9 100644 --- a/src/main/java/leets/weeth/domain/account/application/usecase/ReceiptUseCaseImpl.java +++ b/src/main/java/leets/weeth/domain/account/application/usecase/ReceiptUseCaseImpl.java @@ -9,6 +9,11 @@ import leets.weeth.domain.account.domain.service.ReceiptDeleteService; import leets.weeth.domain.account.domain.service.ReceiptGetService; import leets.weeth.domain.account.domain.service.ReceiptSaveService; +import leets.weeth.domain.file.application.mapper.FileMapper; +import leets.weeth.domain.file.domain.entity.File; +import leets.weeth.domain.file.domain.service.FileDeleteService; +import leets.weeth.domain.file.domain.service.FileGetService; +import leets.weeth.domain.file.domain.service.FileSaveService; import leets.weeth.domain.file.service.S3Service; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -20,25 +25,39 @@ @RequiredArgsConstructor public class ReceiptUseCaseImpl implements ReceiptUseCase { + private final ReceiptGetService receiptGetService; private final ReceiptDeleteService receiptDeleteService; private final ReceiptSaveService receiptSaveService; - private final S3Service s3Service; - private final ReceiptMapper mapper; private final AccountGetService accountGetService; - private final ReceiptGetService receiptGetService; - @Override @Transactional - public void save(ReceiptDTO.Save dto, List files) { - List images = s3Service.uploadFiles(files); + private final FileGetService fileGetService; + private final FileSaveService fileSaveService; + private final FileDeleteService fileDeleteService; + + private final ReceiptMapper mapper; + private final FileMapper fileMapper; + + + @Override + @Transactional + public void save(ReceiptDTO.Save dto) { Account account = accountGetService.find(dto.cardinal()); - Receipt receipt = receiptSaveService.save(mapper.from(dto, images, account)); + Receipt receipt = receiptSaveService.save(mapper.from(dto, account)); account.spend(receipt); + + List files = fileMapper.toFileList(dto.files(), receipt); + fileSaveService.save(files); } - @Override @Transactional + @Override + @Transactional public void delete(Long id) { Receipt receipt = receiptGetService.find(id); + List fileList = fileGetService.findAllByReceipt(id); + receipt.getAccount().cancel(receipt); + + fileDeleteService.delete(fileList); receiptDeleteService.delete(receipt); } } From 6b71a7b4651f7acc4bc04790cc8b04c2ea35f14e Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sun, 17 Nov 2024 17:52:43 +0900 Subject: [PATCH 32/41] =?UTF-8?q?refactor:=20=EC=98=81=EC=88=98=EC=A6=9D?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1=EC=8B=9C=20=EB=A9=80=ED=8B=B0=ED=8C=8C?= =?UTF-8?q?=ED=8A=B8=20=ED=8C=8C=EC=9D=BC=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/account/presentation/ReceiptAdminController.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/leets/weeth/domain/account/presentation/ReceiptAdminController.java b/src/main/java/leets/weeth/domain/account/presentation/ReceiptAdminController.java index adaf8b65..df226e7a 100644 --- a/src/main/java/leets/weeth/domain/account/presentation/ReceiptAdminController.java +++ b/src/main/java/leets/weeth/domain/account/presentation/ReceiptAdminController.java @@ -24,10 +24,10 @@ public class ReceiptAdminController { private final ReceiptUseCase receiptUseCase; - @PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + @PostMapping @Operation(summary="회비 사용 내역 기입") - public CommonResponse save(@RequestPart @Valid ReceiptDTO.Save dto, @RequestPart(required = false) List images) { - receiptUseCase.save(dto, images); + public CommonResponse save(@RequestBody @Valid ReceiptDTO.Save dto) { + receiptUseCase.save(dto); return CommonResponse.createSuccess(RECEIPT_SAVE_SUCCESS.getMessage()); } From abe9ebd460e5347bc1bf84cbf769bf6b008db15c Mon Sep 17 00:00:00 2001 From: hyxklee Date: Sun, 17 Nov 2024 17:54:15 +0900 Subject: [PATCH 33/41] =?UTF-8?q?refactor:=20=ED=9A=8C=EB=B9=84=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=EC=8B=9C=20=EC=98=81=EC=88=98=EC=A6=9D?= =?UTF-8?q?=EC=97=90=20=ED=8C=8C=EC=9D=BC=20=ED=95=A8=EA=BB=98=20=EB=B0=98?= =?UTF-8?q?=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usecase/AccountUseCaseImpl.java | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main/java/leets/weeth/domain/account/application/usecase/AccountUseCaseImpl.java b/src/main/java/leets/weeth/domain/account/application/usecase/AccountUseCaseImpl.java index 591b1f34..d2aae767 100644 --- a/src/main/java/leets/weeth/domain/account/application/usecase/AccountUseCaseImpl.java +++ b/src/main/java/leets/weeth/domain/account/application/usecase/AccountUseCaseImpl.java @@ -2,12 +2,16 @@ import leets.weeth.domain.account.application.dto.AccountDTO; import leets.weeth.domain.account.application.dto.ReceiptDTO; +import leets.weeth.domain.account.application.exception.AccountExistsException; import leets.weeth.domain.account.application.mapper.AccountMapper; import leets.weeth.domain.account.application.mapper.ReceiptMapper; import leets.weeth.domain.account.domain.entity.Account; +import leets.weeth.domain.account.domain.entity.Receipt; import leets.weeth.domain.account.domain.service.AccountGetService; import leets.weeth.domain.account.domain.service.AccountSaveService; -import leets.weeth.domain.account.application.exception.AccountExistsException; +import leets.weeth.domain.file.application.dto.response.FileResponse; +import leets.weeth.domain.file.application.mapper.FileMapper; +import leets.weeth.domain.file.domain.service.FileGetService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -19,14 +23,20 @@ public class AccountUseCaseImpl implements AccountUseCase { private final AccountGetService accountGetService; private final AccountSaveService accountSaveService; + private final FileGetService fileGetService; private final AccountMapper accountMapper; private final ReceiptMapper receiptMapper; + private final FileMapper fileMapper; @Override public AccountDTO.Response find(Integer cardinal) { Account account = accountGetService.find(cardinal); - List receipts = receiptMapper.to(account.getReceipts()); - return accountMapper.to(account, receipts); + List receipts = account.getReceipts(); + List response = receipts.stream() + .map(receipt -> receiptMapper.to(receipt, getFiles(receipt.getId()))) + .toList(); + + return accountMapper.to(account, response); } @Override @@ -36,7 +46,13 @@ public void save(AccountDTO.Save dto) { } private void validate(AccountDTO.Save dto) { - if(accountGetService.validate(dto.cardinal())) + if (accountGetService.validate(dto.cardinal())) throw new AccountExistsException(); } + + private List getFiles(Long receiptId) { + return fileGetService.findAllByReceipt(receiptId).stream() + .map(fileMapper::toFileResponse) + .toList(); + } } From 572fb2de28e4ee7f5b1578604e3baceb815daa83 Mon Sep 17 00:00:00 2001 From: hyxklee Date: Tue, 19 Nov 2024 21:54:28 +0900 Subject: [PATCH 34/41] =?UTF-8?q?refactor:=20=EA=B8=B0=EC=A1=B4=20dto=20?= =?UTF-8?q?=EB=B3=80=EC=88=98=EB=AA=85=EA=B3=BC=20=ED=86=B5=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../leets/weeth/domain/account/application/dto/ReceiptDTO.java | 2 +- .../leets/weeth/domain/board/application/dto/NoticeDTO.java | 2 +- .../java/leets/weeth/domain/board/application/dto/PostDTO.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/leets/weeth/domain/account/application/dto/ReceiptDTO.java b/src/main/java/leets/weeth/domain/account/application/dto/ReceiptDTO.java index 03004b90..3a9af7ad 100644 --- a/src/main/java/leets/weeth/domain/account/application/dto/ReceiptDTO.java +++ b/src/main/java/leets/weeth/domain/account/application/dto/ReceiptDTO.java @@ -15,7 +15,7 @@ public record Response( String description, Integer amount, LocalDate date, - List files + List fileUrls ) {} public record Save( diff --git a/src/main/java/leets/weeth/domain/board/application/dto/NoticeDTO.java b/src/main/java/leets/weeth/domain/board/application/dto/NoticeDTO.java index 66043a37..4e73b094 100644 --- a/src/main/java/leets/weeth/domain/board/application/dto/NoticeDTO.java +++ b/src/main/java/leets/weeth/domain/board/application/dto/NoticeDTO.java @@ -25,7 +25,7 @@ public record Save( public record Update( @NotNull String title, @NotNull String content, - @Valid List<@NotNull FileUpdateRequest> files + @Valid List<@NotNull FileUpdateRequest> fileUrls ) { } diff --git a/src/main/java/leets/weeth/domain/board/application/dto/PostDTO.java b/src/main/java/leets/weeth/domain/board/application/dto/PostDTO.java index 62c8ff2b..465f3ec6 100644 --- a/src/main/java/leets/weeth/domain/board/application/dto/PostDTO.java +++ b/src/main/java/leets/weeth/domain/board/application/dto/PostDTO.java @@ -24,7 +24,7 @@ public record Save( public record Update( @NotNull String title, @NotNull String content, - @Valid List<@NotNull FileUpdateRequest> files + @Valid List<@NotNull FileUpdateRequest> fileUrls ){} @Builder From 77f2850edbbc94a4d89b527cc568f7be2e973bad Mon Sep 17 00:00:00 2001 From: hyxklee Date: Tue, 19 Nov 2024 22:00:16 +0900 Subject: [PATCH 35/41] =?UTF-8?q?refactor:=20=EA=B8=B0=EC=A1=B4=20dto=20?= =?UTF-8?q?=EB=B3=80=EC=88=98=EB=AA=85=EA=B3=BC=20=ED=86=B5=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../leets/weeth/domain/board/application/dto/NoticeDTO.java | 4 ++-- .../leets/weeth/domain/board/application/dto/PostDTO.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/leets/weeth/domain/board/application/dto/NoticeDTO.java b/src/main/java/leets/weeth/domain/board/application/dto/NoticeDTO.java index 4e73b094..fa80b2cf 100644 --- a/src/main/java/leets/weeth/domain/board/application/dto/NoticeDTO.java +++ b/src/main/java/leets/weeth/domain/board/application/dto/NoticeDTO.java @@ -25,7 +25,7 @@ public record Save( public record Update( @NotNull String title, @NotNull String content, - @Valid List<@NotNull FileUpdateRequest> fileUrls + @Valid List<@NotNull FileUpdateRequest> files ) { } @@ -38,7 +38,7 @@ public record Response( LocalDateTime time,//modifiedAt Integer commentCount, List comments, - List files + List fileUrls ) { } diff --git a/src/main/java/leets/weeth/domain/board/application/dto/PostDTO.java b/src/main/java/leets/weeth/domain/board/application/dto/PostDTO.java index 465f3ec6..0ca4b5e2 100644 --- a/src/main/java/leets/weeth/domain/board/application/dto/PostDTO.java +++ b/src/main/java/leets/weeth/domain/board/application/dto/PostDTO.java @@ -24,7 +24,7 @@ public record Save( public record Update( @NotNull String title, @NotNull String content, - @Valid List<@NotNull FileUpdateRequest> fileUrls + @Valid List<@NotNull FileUpdateRequest> files ){} @Builder @@ -36,7 +36,7 @@ public record Response( LocalDateTime time,//modifiedAt Integer commentCount, List comments, - List files + List fileUrls ){} @Builder From b19abcfc1a055602bd1738f7d4e1862ebb2ccf3d Mon Sep 17 00:00:00 2001 From: hyxklee Date: Tue, 19 Nov 2024 23:01:15 +0900 Subject: [PATCH 36/41] =?UTF-8?q?refactor:=20dto=20=EB=B3=80=EC=88=98?= =?UTF-8?q?=EB=AA=85=20=ED=86=B5=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weeth/domain/account/application/mapper/ReceiptMapper.java | 2 +- .../weeth/domain/board/application/mapper/NoticeMapper.java | 2 +- .../weeth/domain/board/application/mapper/PostMapper.java | 2 +- .../leets/weeth/domain/file/application/mapper/FileMapper.java | 3 +++ 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/leets/weeth/domain/account/application/mapper/ReceiptMapper.java b/src/main/java/leets/weeth/domain/account/application/mapper/ReceiptMapper.java index 725597b3..bfcbb5d7 100644 --- a/src/main/java/leets/weeth/domain/account/application/mapper/ReceiptMapper.java +++ b/src/main/java/leets/weeth/domain/account/application/mapper/ReceiptMapper.java @@ -16,7 +16,7 @@ public interface ReceiptMapper { List to(List account); - ReceiptDTO.Response to(Receipt receipt, List files); + ReceiptDTO.Response to(Receipt receipt, List fileUrls); @Mapping(target = "id", ignore = true) @Mapping(target = "description", source = "dto.description") diff --git a/src/main/java/leets/weeth/domain/board/application/mapper/NoticeMapper.java b/src/main/java/leets/weeth/domain/board/application/mapper/NoticeMapper.java index 05e8f564..db9e2098 100644 --- a/src/main/java/leets/weeth/domain/board/application/mapper/NoticeMapper.java +++ b/src/main/java/leets/weeth/domain/board/application/mapper/NoticeMapper.java @@ -34,7 +34,7 @@ public interface NoticeMapper { @Mapping(target = "comments", expression = "java(filterParentComments(notice.getComments()))"), @Mapping(target = "time", source = "notice.modifiedAt") }) - NoticeDTO.Response toNoticeDto(Notice notice, List files); + NoticeDTO.Response toNoticeDto(Notice notice, List fileUrls); default List filterParentComments(List comments) { if (comments == null || comments.isEmpty()) { diff --git a/src/main/java/leets/weeth/domain/board/application/mapper/PostMapper.java b/src/main/java/leets/weeth/domain/board/application/mapper/PostMapper.java index dcb298dc..27474fff 100644 --- a/src/main/java/leets/weeth/domain/board/application/mapper/PostMapper.java +++ b/src/main/java/leets/weeth/domain/board/application/mapper/PostMapper.java @@ -33,7 +33,7 @@ public interface PostMapper { @Mapping(target = "comments", expression = "java(filterParentComments(post.getComments()))"), @Mapping(target = "time", source = "post.modifiedAt") }) - PostDTO.Response toPostDto(Post post, List files); + PostDTO.Response toPostDto(Post post, List fileUrls); default List filterParentComments(List comments) { if (comments == null || comments.isEmpty()) { diff --git a/src/main/java/leets/weeth/domain/file/application/mapper/FileMapper.java b/src/main/java/leets/weeth/domain/file/application/mapper/FileMapper.java index c5ab0379..efc5a303 100644 --- a/src/main/java/leets/weeth/domain/file/application/mapper/FileMapper.java +++ b/src/main/java/leets/weeth/domain/file/application/mapper/FileMapper.java @@ -20,12 +20,15 @@ @Mapper(componentModel = MappingConstants.ComponentModel.SPRING, uses = CommentMapper.class, unmappedTargetPolicy = ReportingPolicy.IGNORE) public interface FileMapper { + @Mapping(target = "id", ignore = true) @Mapping(target = "post", source = "post") File toFile(String fileName, String fileUrl, Post post); + @Mapping(target = "id", ignore = true) @Mapping(target = "notice", source = "notice") File toFile(String fileName, String fileUrl, Notice notice); + @Mapping(target = "id", ignore = true) @Mapping(target = "receipt", source = "receipt") File toFile(String fileName, String fileUrl, Receipt receipt); From 7c4b6540aa64bbf30378474d8a2df76dd330b578 Mon Sep 17 00:00:00 2001 From: hyxklee Date: Tue, 19 Nov 2024 23:01:22 +0900 Subject: [PATCH 37/41] =?UTF-8?q?refactor:=20dto=20=EC=9C=A0=ED=9A=A8?= =?UTF-8?q?=EC=84=B1=20=EA=B2=80=EC=82=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/file/application/dto/request/FileSaveRequest.java | 2 +- .../domain/file/application/dto/request/FileUpdateRequest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/leets/weeth/domain/file/application/dto/request/FileSaveRequest.java b/src/main/java/leets/weeth/domain/file/application/dto/request/FileSaveRequest.java index 4d705c6f..73921fab 100644 --- a/src/main/java/leets/weeth/domain/file/application/dto/request/FileSaveRequest.java +++ b/src/main/java/leets/weeth/domain/file/application/dto/request/FileSaveRequest.java @@ -5,6 +5,6 @@ public record FileSaveRequest( @NotBlank String fileName, - @URL String fileUrl + @NotBlank @URL String fileUrl ) { } diff --git a/src/main/java/leets/weeth/domain/file/application/dto/request/FileUpdateRequest.java b/src/main/java/leets/weeth/domain/file/application/dto/request/FileUpdateRequest.java index ee024ef5..08679460 100644 --- a/src/main/java/leets/weeth/domain/file/application/dto/request/FileUpdateRequest.java +++ b/src/main/java/leets/weeth/domain/file/application/dto/request/FileUpdateRequest.java @@ -6,6 +6,6 @@ public record FileUpdateRequest( @NotBlank Long fileId, @NotBlank String fileName, - @URL String fileUrl + @NotBlank @URL String fileUrl ) { } From 4f46cf39ab349c8f41663fb24fd942a310ebe9cf Mon Sep 17 00:00:00 2001 From: hyxklee Date: Wed, 20 Nov 2024 21:40:46 +0900 Subject: [PATCH 38/41] =?UTF-8?q?refactor:=20dto=20=EC=9C=A0=ED=9A=A8?= =?UTF-8?q?=EC=84=B1=20=EA=B2=80=EC=82=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/file/application/dto/request/FileUpdateRequest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/leets/weeth/domain/file/application/dto/request/FileUpdateRequest.java b/src/main/java/leets/weeth/domain/file/application/dto/request/FileUpdateRequest.java index 08679460..51544cf6 100644 --- a/src/main/java/leets/weeth/domain/file/application/dto/request/FileUpdateRequest.java +++ b/src/main/java/leets/weeth/domain/file/application/dto/request/FileUpdateRequest.java @@ -1,10 +1,11 @@ package leets.weeth.domain.file.application.dto.request; import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; import org.hibernate.validator.constraints.URL; public record FileUpdateRequest( - @NotBlank Long fileId, + @NotNull Long fileId, @NotBlank String fileName, @NotBlank @URL String fileUrl ) { From d4a5f6120de54fa61a3df7c1a70257a9dd6afbe6 Mon Sep 17 00:00:00 2001 From: hyxklee Date: Fri, 22 Nov 2024 01:28:25 +0900 Subject: [PATCH 39/41] =?UTF-8?q?refactor:=20=EA=B2=8C=EC=8B=9C=EA=B8=80(f?= =?UTF-8?q?ile)=20=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../leets/weeth/domain/board/application/dto/PostDTO.java | 2 +- .../domain/board/application/usecase/PostUseCaseImpl.java | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/leets/weeth/domain/board/application/dto/PostDTO.java b/src/main/java/leets/weeth/domain/board/application/dto/PostDTO.java index 0ca4b5e2..918c21a3 100644 --- a/src/main/java/leets/weeth/domain/board/application/dto/PostDTO.java +++ b/src/main/java/leets/weeth/domain/board/application/dto/PostDTO.java @@ -24,7 +24,7 @@ public record Save( public record Update( @NotNull String title, @NotNull String content, - @Valid List<@NotNull FileUpdateRequest> files + @Valid List<@NotNull FileSaveRequest> files ){} @Builder diff --git a/src/main/java/leets/weeth/domain/board/application/usecase/PostUseCaseImpl.java b/src/main/java/leets/weeth/domain/board/application/usecase/PostUseCaseImpl.java index 0da7dc3f..552d69f7 100644 --- a/src/main/java/leets/weeth/domain/board/application/usecase/PostUseCaseImpl.java +++ b/src/main/java/leets/weeth/domain/board/application/usecase/PostUseCaseImpl.java @@ -98,8 +98,10 @@ public void update(Long postId, PostDTO.Update dto, Long userId) { Post post = validateOwner(postId, userId); List fileList = getFiles(postId); + fileDeleteService.delete(fileList); - fileUpdateService.updateFiles(fileList, dto.files()); + List files = fileMapper.toFileList(dto.files(), post); + fileSaveService.save(files); postUpdateService.update(post, dto); } From 1feab2479d39e1b4058c4ea1ad572cb8aace8f9d Mon Sep 17 00:00:00 2001 From: hyxklee Date: Fri, 22 Nov 2024 19:47:25 +0900 Subject: [PATCH 40/41] =?UTF-8?q?refactor:=20=EA=B3=B5=EC=A7=80=EC=82=AC?= =?UTF-8?q?=ED=95=AD=20=EC=88=98=EC=A0=95=20=EB=A1=9C=EC=A7=81=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../leets/weeth/domain/board/application/dto/NoticeDTO.java | 2 +- .../domain/board/application/usecase/NoticeUsecaseImpl.java | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/leets/weeth/domain/board/application/dto/NoticeDTO.java b/src/main/java/leets/weeth/domain/board/application/dto/NoticeDTO.java index fa80b2cf..44540214 100644 --- a/src/main/java/leets/weeth/domain/board/application/dto/NoticeDTO.java +++ b/src/main/java/leets/weeth/domain/board/application/dto/NoticeDTO.java @@ -25,7 +25,7 @@ public record Save( public record Update( @NotNull String title, @NotNull String content, - @Valid List<@NotNull FileUpdateRequest> files + @Valid List<@NotNull FileSaveRequest> files ) { } diff --git a/src/main/java/leets/weeth/domain/board/application/usecase/NoticeUsecaseImpl.java b/src/main/java/leets/weeth/domain/board/application/usecase/NoticeUsecaseImpl.java index 687b8189..9024b9a7 100644 --- a/src/main/java/leets/weeth/domain/board/application/usecase/NoticeUsecaseImpl.java +++ b/src/main/java/leets/weeth/domain/board/application/usecase/NoticeUsecaseImpl.java @@ -98,8 +98,10 @@ public void update(Long noticeId, NoticeDTO.Update dto, Long userId) { Notice notice = validateOwner(noticeId, userId); List fileList = getFiles(noticeId); + fileDeleteService.delete(fileList); - fileUpdateService.updateFiles(fileList, dto.files()); + List files = fileMapper.toFileList(dto.files(), notice); + fileSaveService.save(files); noticeUpdateService.update(notice, dto); } From e600e462f40d7c7cee8c530507d1bbd817c96cbd Mon Sep 17 00:00:00 2001 From: hyxklee Date: Fri, 22 Nov 2024 19:51:59 +0900 Subject: [PATCH 41/41] =?UTF-8?q?refactor:=20=EB=A9=94=EC=84=9C=EB=93=9C?= =?UTF-8?q?=20=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/file/application/mapper/FileMapper.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/leets/weeth/domain/file/application/mapper/FileMapper.java b/src/main/java/leets/weeth/domain/file/application/mapper/FileMapper.java index efc5a303..13fd228a 100644 --- a/src/main/java/leets/weeth/domain/file/application/mapper/FileMapper.java +++ b/src/main/java/leets/weeth/domain/file/application/mapper/FileMapper.java @@ -22,15 +22,15 @@ public interface FileMapper { @Mapping(target = "id", ignore = true) @Mapping(target = "post", source = "post") - File toFile(String fileName, String fileUrl, Post post); + File toFileWithPost(String fileName, String fileUrl, Post post); @Mapping(target = "id", ignore = true) @Mapping(target = "notice", source = "notice") - File toFile(String fileName, String fileUrl, Notice notice); + File toFileWithNotice(String fileName, String fileUrl, Notice notice); @Mapping(target = "id", ignore = true) @Mapping(target = "receipt", source = "receipt") - File toFile(String fileName, String fileUrl, Receipt receipt); + File toFileWithReceipt(String fileName, String fileUrl, Receipt receipt); @Mapping(target = "fileId", source = "file.id") FileResponse toFileResponse(File file); @@ -44,7 +44,7 @@ default List toFileList(List requests, Post post) { } return dto.stream() - .map(request -> toFile(request.fileName(), request.fileUrl(), post)) + .map(request -> toFileWithPost(request.fileName(), request.fileUrl(), post)) .collect(Collectors.toList()); } @@ -54,7 +54,7 @@ default List toFileList(List requests, Notice notice) { } return requests.stream() - .map(request -> toFile(request.fileName(), request.fileUrl(), notice)) + .map(request -> toFileWithNotice(request.fileName(), request.fileUrl(), notice)) .collect(Collectors.toList()); } @@ -64,7 +64,7 @@ default List toFileList(List requests, Receipt receipt) { } return requests.stream() - .map(request -> toFile(request.fileName(), request.fileUrl(), receipt)) + .map(request -> toFileWithReceipt(request.fileName(), request.fileUrl(), receipt)) .collect(Collectors.toList()); } }