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 7fbcafd7..8ed9b3ca 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 @@ -32,4 +32,15 @@ public record Response( List fileUrls, List comments ){} + + @Builder + public record ResponseAll( + Long id, + String name, + String title, + 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 d9738632..450271f4 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 @@ -33,4 +33,14 @@ public record Response( List comments ){} + @Builder + public record ResponseAll( + Long id, + String name, + String title, + String content, + LocalDateTime time,//modifiedAt + Integer commentCount + ){} + } 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 c17ba049..8dff57f7 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 @@ -21,9 +21,11 @@ public interface NoticeMapper { }) Notice fromNoticeDto(NoticeDTO.Save dto, List fileUrls, User user); -// @Mapping(target = "id", source = "noticeId") -// @Mapping(target = "user", source = "user") -// Notice update(Long noticeId, NoticeDTO.Update dto, List fileUrls, User user); + @Mappings({ + @Mapping(target = "name", source = "user.name"), + @Mapping(target = "time", source = "modifiedAt") + }) + NoticeDTO.ResponseAll toAll(Notice notice); @Mappings({ @Mapping(target = "name", source = "user.name"), @@ -41,7 +43,7 @@ default List filterParentComments(List comments) { return comments.stream() .filter(comment -> comment.getParent() == null) // 부모 댓글만 필터링 .map(this::mapCommentWithChildren) // 자식 댓글 포함하여 매핑 - .collect(Collectors.toList()); + .toList(); } default CommentDTO.Response mapCommentWithChildren(Comment comment) { @@ -66,7 +68,4 @@ default CommentDTO.Response mapCommentWithChildren(Comment comment) { return response.build(); } - @Mapping(target = "name", source = "user.name") - @Mapping(target = "time", source = "modifiedAt") - CommentDTO.Response mapComment(Comment comment); } 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 c91d9733..ecb55f77 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 @@ -21,9 +21,11 @@ public interface PostMapper { }) Post fromPostDto(PostDTO.Save dto, List fileUrls, User user); -// @Mapping(target = "id", source = "postId") -// @Mapping(target = "user", source = "user") -// Post update(Long postId, PostDTO.Update dto, User user); + @Mappings({ + @Mapping(target = "name", source = "user.name"), + @Mapping(target = "time", source = "modifiedAt") + }) + PostDTO.ResponseAll toAll(Post post); @Mappings({ @Mapping(target = "name", source = "user.name"), @@ -41,7 +43,7 @@ default List filterParentComments(List comments) { return comments.stream() .filter(comment -> comment.getParent() == null) // 부모 댓글만 필터링 .map(this::mapCommentWithChildren) // 자식 댓글 포함하여 매핑 - .collect(Collectors.toList()); + .toList(); } default CommentDTO.Response mapCommentWithChildren(Comment comment) { @@ -66,8 +68,4 @@ default CommentDTO.Response mapCommentWithChildren(Comment comment) { return response.build(); } - @Mapping(target = "name", source = "user.name") - @Mapping(target = "time", source = "modifiedAt") - CommentDTO.Response mapComment(Comment comment); - } 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 04125c5b..bba5fb5e 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 @@ -13,7 +13,7 @@ public interface NoticeUsecase { NoticeDTO.Response findNotice(Long noticeId); - List findNotices(Long noticeId, Integer count); + List findNotices(Long noticeId, Integer count); void update(Long noticeId, NoticeDTO.Update dto, List files, 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 cdf090eb..a7947b36 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 @@ -50,7 +50,7 @@ public NoticeDTO.Response findNotice(Long noticeId) { } @Override - public List findNotices(Long noticeId, Integer count) { + public List findNotices(Long noticeId, Integer count) { Long finalNoticeId = noticeFindService.findFinalNoticeId(); @@ -66,7 +66,7 @@ public List findNotices(Long noticeId, Integer count) { List notices = noticeFindService.findRecentNotices(noticeId, pageable); return notices.stream() - .map(mapper::toNoticeDto) + .map(mapper::toAll) .toList(); } 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 91720f78..a4240a43 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 @@ -52,7 +52,7 @@ public PostDTO.Response findPost(Long postId) { } @Override - public List findPosts(Long postId, Integer count) { + public List findPosts(Long postId, Integer count) { Long finalPostId = postFindService.findFinalPostId(); @@ -68,7 +68,7 @@ public List findPosts(Long postId, Integer count) { List posts = postFindService.findRecentPosts(postId, pageable); return posts.stream() - .map(mapper::toPostDto) + .map(mapper::toAll) .toList(); } 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 577fba7a..f4f39878 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 @@ -13,7 +13,7 @@ public interface PostUsecase { PostDTO.Response findPost(Long postId); - List findPosts(Long postId, Integer count); + List findPosts(Long postId, Integer count); void update(Long postId, PostDTO.Update dto, List files, Long userId) throws UserNotMatchException; diff --git a/src/main/java/leets/weeth/domain/board/presentation/NoticeController.java b/src/main/java/leets/weeth/domain/board/presentation/NoticeController.java index 5203a867..65516efb 100644 --- a/src/main/java/leets/weeth/domain/board/presentation/NoticeController.java +++ b/src/main/java/leets/weeth/domain/board/presentation/NoticeController.java @@ -17,7 +17,7 @@ public class NoticeController { private final NoticeUsecase noticeUsecase; @GetMapping - public CommonResponse> findNotices(@RequestParam(required = false) Long noticeId, @RequestParam Integer count) { + public CommonResponse> findNotices(@RequestParam(required = false) Long noticeId, @RequestParam Integer count) { return CommonResponse.createSuccess(noticeUsecase.findNotices(noticeId, count)); } 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 5e11619f..d5391272 100644 --- a/src/main/java/leets/weeth/domain/board/presentation/PostController.java +++ b/src/main/java/leets/weeth/domain/board/presentation/PostController.java @@ -30,7 +30,7 @@ public CommonResponse save(@RequestPart @Valid PostDTO.Save dto, } @GetMapping - public CommonResponse> findPosts(@RequestParam(required = false) Long postId, @RequestParam Integer count) { + public CommonResponse> findPosts(@RequestParam(required = false) Long postId, @RequestParam Integer count) { return CommonResponse.createSuccess(postUsecase.findPosts(postId, count)); } diff --git a/src/main/java/leets/weeth/domain/comment/application/mapper/CommentMapper.java b/src/main/java/leets/weeth/domain/comment/application/mapper/CommentMapper.java index d0b180b3..6ffdc25a 100644 --- a/src/main/java/leets/weeth/domain/comment/application/mapper/CommentMapper.java +++ b/src/main/java/leets/weeth/domain/comment/application/mapper/CommentMapper.java @@ -19,7 +19,7 @@ public interface CommentMapper { @Mapping(target = "user", source = "user"), @Mapping(target = "parent", source = "parent"), @Mapping(target = "content", source = "dto.content"), - @Mapping(target = "post", source = "post"), + @Mapping(target = "post", source = "post") }) Comment fromCommentDto(CommentDTO.Save dto, Post post, User user, Comment parent); @@ -32,13 +32,11 @@ public interface CommentMapper { @Mapping(target = "user", source = "user"), @Mapping(target = "parent", source = "parent"), @Mapping(target = "content", source = "dto.content"), - @Mapping(target = "notice", source = "notice"), - + @Mapping(target = "notice", source = "notice") }) Comment fromCommentDto(CommentDTO.Save dto, Notice notice, User user, Comment parent); @Mapping(target = "name", source = "user.name") @Mapping(target = "time", source = "modifiedAt") CommentDTO.Response toCommentDto(Comment comment); - } diff --git a/src/main/java/leets/weeth/domain/comment/application/usecase/NoticeCommentUsecaseImpl.java b/src/main/java/leets/weeth/domain/comment/application/usecase/NoticeCommentUsecaseImpl.java index 544de51e..639f176d 100644 --- a/src/main/java/leets/weeth/domain/comment/application/usecase/NoticeCommentUsecaseImpl.java +++ b/src/main/java/leets/weeth/domain/comment/application/usecase/NoticeCommentUsecaseImpl.java @@ -54,6 +54,7 @@ public void saveNoticeComment(CommentDTO.Save dto, Long noticeId, Long userId) { notice.incrementCommentCount(); } + @Override @Transactional public void updateNoticeComment(CommentDTO.Update dto, Long noticeId, Long commentId, Long userId) throws UserNotMatchException {