From 072328d0abb1d3a0d0a5d172053f7a2dd9eb759d Mon Sep 17 00:00:00 2001 From: jinho7 <69239293+jinho7@users.noreply.github.com> Date: Sat, 17 Aug 2024 16:54:31 +0900 Subject: [PATCH 1/4] =?UTF-8?q?=E2=9C=A8=20feat:=20=EB=A7=88=EC=9D=B4?= =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=A7=80=20=EC=BB=A4=EB=AE=A4=EB=8B=88?= =?UTF-8?q?=ED=8B=B0=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../board/controller/BoardController.java | 31 ++++++- .../board/controller/CommentController.java | 2 +- .../board/dto/response/BoardResponseDTO.java | 12 --- .../board/repository/BoardRepository.java | 19 ++--- .../queryService/BoardQueryService.java | 8 +- .../queryService/BoardQueryServiceImpl.java | 82 +++++++++++++------ .../member/controller/MemberController.java | 1 - 7 files changed, 100 insertions(+), 55 deletions(-) diff --git a/src/main/java/com/example/template/domain/board/controller/BoardController.java b/src/main/java/com/example/template/domain/board/controller/BoardController.java index 5c5c0d3..4c76fcf 100644 --- a/src/main/java/com/example/template/domain/board/controller/BoardController.java +++ b/src/main/java/com/example/template/domain/board/controller/BoardController.java @@ -48,13 +48,40 @@ public ApiResponse getBoardList( @Operation(summary = "게시글 상세 조회", description = "지정된 ID의 게시글 상세 정보를 조회합니다.") @GetMapping("/{boardId}") - public ApiResponse getBoardDetail(@PathVariable("boardId") Long boardId, + public ApiResponse getBoardDetail(@PathVariable("boardId") Long boardId, @AuthenticatedMember Member member) { return ApiResponse.onSuccess(boardQueryService.getBoardDetail(boardId, member)); } + @Operation(summary = "내가 쓴 게시글 조회", description = "사용자가 작성한 게시글 목록을 최신순으로 커서 기반 페이지네이션으로 조회합니다.") + @GetMapping("/my-posts") + public ApiResponse getMyPosts( + @RequestParam(defaultValue = "0") Long cursor, + @RequestParam(defaultValue = "10") Integer limit, + @AuthenticatedMember Member member) { + return ApiResponse.onSuccess(boardQueryService.getMyPosts(cursor, limit, member)); + } + + @Operation(summary = "내가 댓글 단 게시글 조회", description = "사용자가 댓글을 작성한 게시글 목록을 최신순으로 커서 기반 페이지네이션으로 조회합니다.") + @GetMapping("/my-comments") + public ApiResponse getMyCommentedPosts( + @RequestParam(defaultValue = "0") Long cursor, + @RequestParam(defaultValue = "10") Integer limit, + @AuthenticatedMember Member member) { + return ApiResponse.onSuccess(boardQueryService.getMyCommentedPosts(cursor, limit, member)); + } + + @Operation(summary = "내가 좋아요 한 게시글 조회", description = "사용자가 좋아요를 누른 게시글 목록을 최신순으로 커서 기반 페이지네이션으로 조회합니다.") + @GetMapping("/my-likes") + public ApiResponse getMyLikedPosts( + @RequestParam(defaultValue = "0") Long cursor, + @RequestParam(defaultValue = "10") Integer limit, + @AuthenticatedMember Member member) { + return ApiResponse.onSuccess(boardQueryService.getMyLikedPosts(cursor, limit, member)); + } + // CommandService - @Operation(summary = "이미지 업로드", description = "게시글에 첨부할 이미지를 업로드합니다.") + @Operation(summary = "커뮤니티 게시글 이미지 업로드", description = "게시글에 첨부할 이미지를 업로드합니다.") @PostMapping(value = "/images", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public ApiResponse uploadBoardImages( @RequestPart("images") List images) { diff --git a/src/main/java/com/example/template/domain/board/controller/CommentController.java b/src/main/java/com/example/template/domain/board/controller/CommentController.java index f862272..5f574ef 100644 --- a/src/main/java/com/example/template/domain/board/controller/CommentController.java +++ b/src/main/java/com/example/template/domain/board/controller/CommentController.java @@ -39,7 +39,7 @@ public ApiResponse getComments( } // CommandService - @Operation(summary = "이미지 업로드", description = "댓글에 첨부할 이미지를 업로드합니다.") + @Operation(summary = "커뮤니티 댓글 이미지 업로드", description = "댓글에 첨부할 이미지를 업로드합니다.") @PostMapping(value = "/comments/images", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public ApiResponse uploadCommentImages( @RequestPart("images") List images) { diff --git a/src/main/java/com/example/template/domain/board/dto/response/BoardResponseDTO.java b/src/main/java/com/example/template/domain/board/dto/response/BoardResponseDTO.java index 7ad0adc..c987991 100644 --- a/src/main/java/com/example/template/domain/board/dto/response/BoardResponseDTO.java +++ b/src/main/java/com/example/template/domain/board/dto/response/BoardResponseDTO.java @@ -76,18 +76,6 @@ public static BoardListDTO of(List boards, Long nextCursor, boolean hasNe } } - @Getter - @Builder - public static class BoardDetailDTO { - private BoardDTO board; - - public static BoardDetailDTO of(Board board, Member currentMember) { - return BoardDetailDTO.builder() - .board(BoardDTO.from(board, currentMember.getId())) - .build(); - } - } - @Getter @Builder public static class BoardStatusDTO { diff --git a/src/main/java/com/example/template/domain/board/repository/BoardRepository.java b/src/main/java/com/example/template/domain/board/repository/BoardRepository.java index cdceb43..891564a 100644 --- a/src/main/java/com/example/template/domain/board/repository/BoardRepository.java +++ b/src/main/java/com/example/template/domain/board/repository/BoardRepository.java @@ -26,20 +26,13 @@ public interface BoardRepository extends JpaRepository { @Query("SELECT b FROM Board b WHERE b.category = :category AND b.id < :cursor ORDER BY b.id DESC") List findByCategoryOrderByLatestWithCursor(@Param("category") Category category, @Param("cursor") Long cursor, Pageable pageable); - default List findAllOrderByLikesWithCursor(Long cursor, Integer limit) { - return findAllOrderByLikesWithCursor(cursor, PageRequest.of(0, limit)); - } + @Query("SELECT b FROM Board b WHERE b.member.id = :memberId AND b.id < :cursor ORDER BY b.id DESC") + List findMyPosts(@Param("memberId") Long memberId, @Param("cursor") Long cursor, Pageable pageable); - default List findAllOrderByLatestWithCursor(Long cursor, Integer limit) { - return findAllOrderByLatestWithCursor(cursor, PageRequest.of(0, limit)); - } + @Query("SELECT DISTINCT b FROM Board b JOIN b.comments c WHERE c.member.id = :memberId AND b.id < :cursor ORDER BY b.id DESC") + List findMyCommentedPosts(@Param("memberId") Long memberId, @Param("cursor") Long cursor, Pageable pageable); - default List findByCategoryOrderByLikesWithCursor(Category category, Long cursor, Integer limit) { - return findByCategoryOrderByLikesWithCursor(category, cursor, PageRequest.of(0, limit)); - } - - default List findByCategoryOrderByLatestWithCursor(Category category, Long cursor, Integer limit) { - return findByCategoryOrderByLatestWithCursor(category, cursor, PageRequest.of(0, limit)); - } + @Query("SELECT b FROM Board b JOIN BoardLike bl ON b.id = bl.board.id WHERE bl.member.id = :memberId AND b.id < :cursor ORDER BY b.id DESC") + List findMyLikedPosts(@Param("memberId") Long memberId, @Param("cursor") Long cursor, Pageable pageable); } diff --git a/src/main/java/com/example/template/domain/board/service/queryService/BoardQueryService.java b/src/main/java/com/example/template/domain/board/service/queryService/BoardQueryService.java index 5d4d687..5522879 100644 --- a/src/main/java/com/example/template/domain/board/service/queryService/BoardQueryService.java +++ b/src/main/java/com/example/template/domain/board/service/queryService/BoardQueryService.java @@ -13,5 +13,11 @@ BoardResponseDTO.BoardListDTO getBoardList(Category category, SortType sortType, Member member); - BoardResponseDTO.BoardDetailDTO getBoardDetail(Long boardId, Member member); + BoardResponseDTO.BoardDTO getBoardDetail(Long boardId, Member member); + + BoardResponseDTO.BoardListDTO getMyPosts(Long cursor, Integer limit, Member member); + + BoardResponseDTO.BoardListDTO getMyCommentedPosts(Long cursor, Integer limit, Member member); + + BoardResponseDTO.BoardListDTO getMyLikedPosts(Long cursor, Integer limit, Member member); } \ No newline at end of file diff --git a/src/main/java/com/example/template/domain/board/service/queryService/BoardQueryServiceImpl.java b/src/main/java/com/example/template/domain/board/service/queryService/BoardQueryServiceImpl.java index b9ea624..3d66b4e 100644 --- a/src/main/java/com/example/template/domain/board/service/queryService/BoardQueryServiceImpl.java +++ b/src/main/java/com/example/template/domain/board/service/queryService/BoardQueryServiceImpl.java @@ -9,6 +9,7 @@ import com.example.template.domain.board.repository.BoardRepository; import com.example.template.domain.member.entity.Member; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -27,35 +28,66 @@ public BoardResponseDTO.BoardListDTO getBoardList(Category category, Integer limit, SortType sortType, Member member) { - // 첫 페이지 로딩 시 매우 큰 ID 값 사용 - if (cursor == 0) { - cursor = Long.MAX_VALUE; - } - - List boards; - // 전체 조회 - if (category == null) { - boards = sortType == SortType.LIKES - ? boardRepository.findAllOrderByLikesWithCursor(cursor, limit) - : boardRepository.findAllOrderByLatestWithCursor(cursor, limit); - } - // 카테고리별 조회 - else { - boards = sortType == SortType.LIKES - ? boardRepository.findByCategoryOrderByLikesWithCursor(category, cursor, limit) - : boardRepository.findByCategoryOrderByLatestWithCursor(category, cursor, limit); - } - - Long nextCursor = boards.isEmpty() ? null : boards.get(boards.size() - 1).getId(); - boolean hasNext = boards.size() == limit; - - return BoardResponseDTO.BoardListDTO.of(boards, nextCursor, hasNext, member.getId()); + cursor = initializeCursor(cursor); + List boards = fetchBoards(category, cursor, limit, sortType); + return createBoardListDTO(boards, limit, member.getId()); } @Override - public BoardResponseDTO.BoardDetailDTO getBoardDetail(Long boardId, Member member) { + public BoardResponseDTO.BoardDTO getBoardDetail(Long boardId, Member member) { Board board = boardRepository.findById(boardId) .orElseThrow(() -> new BoardException(BoardErrorCode.BOARD_NOT_FOUND)); - return BoardResponseDTO.BoardDetailDTO.of(board, member); + return BoardResponseDTO.BoardDTO.from(board, member.getId()); + } + + public BoardResponseDTO.BoardListDTO getMyPosts(Long cursor, Integer limit, Member member) { + cursor = initializeCursor(cursor); + PageRequest pageRequest = PageRequest.of(0, limit + 1); + List boards = boardRepository.findMyPosts(member.getId(), cursor, pageRequest); + return createBoardListDTO(boards, limit, member.getId()); + } + + public BoardResponseDTO.BoardListDTO getMyCommentedPosts(Long cursor, Integer limit, Member member) { + cursor = initializeCursor(cursor); + PageRequest pageRequest = PageRequest.of(0, limit + 1); + List boards = boardRepository.findMyCommentedPosts(member.getId(), cursor, pageRequest); + return createBoardListDTO(boards, limit, member.getId()); + } + + public BoardResponseDTO.BoardListDTO getMyLikedPosts(Long cursor, Integer limit, Member member) { + cursor = initializeCursor(cursor); + PageRequest pageRequest = PageRequest.of(0, limit + 1); + List boards = boardRepository.findMyLikedPosts(member.getId(), cursor, pageRequest); + return createBoardListDTO(boards, limit, member.getId()); + } + + private Long initializeCursor(Long cursor) { + return (cursor == 0) ? Long.MAX_VALUE : cursor; + } + + private List fetchBoards(Category category, Long cursor, Integer limit, SortType sortType) { + PageRequest pageRequest = PageRequest.of(0, limit + 1); + if (category == null) { + if (sortType == SortType.LIKES) { + return boardRepository.findAllOrderByLikesWithCursor(cursor, pageRequest); + } else { + return boardRepository.findAllOrderByLatestWithCursor(cursor, pageRequest); + } + } else { + if (sortType == SortType.LIKES) { + return boardRepository.findByCategoryOrderByLikesWithCursor(category, cursor, pageRequest); + } else { + return boardRepository.findByCategoryOrderByLatestWithCursor(category, cursor, pageRequest); + } + } + } + + private BoardResponseDTO.BoardListDTO createBoardListDTO(List boards, Integer limit, Long memberId) { + boolean hasNext = boards.size() > limit; + if (hasNext) { + boards = boards.subList(0, limit); + } + Long nextCursor = hasNext ? boards.get(boards.size() - 1).getId() : null; + return BoardResponseDTO.BoardListDTO.of(boards, nextCursor, hasNext, memberId); } } diff --git a/src/main/java/com/example/template/domain/member/controller/MemberController.java b/src/main/java/com/example/template/domain/member/controller/MemberController.java index 48f78b1..b63b7e6 100644 --- a/src/main/java/com/example/template/domain/member/controller/MemberController.java +++ b/src/main/java/com/example/template/domain/member/controller/MemberController.java @@ -40,7 +40,6 @@ public ApiResponse loginOrSignupByKakao(@Valid return ApiResponse.onSuccess(kakaoService.loginOrSignupByKakao(requestDTO)); } - @Operation(summary = "로그아웃") @PostMapping("/logout") public ApiResponse logout(HttpServletRequest request) { From cd64c73c860d3f6e7bce47196262541bf2f2c8a8 Mon Sep 17 00:00:00 2001 From: jinho7 <69239293+jinho7@users.noreply.github.com> Date: Sat, 17 Aug 2024 20:02:21 +0900 Subject: [PATCH 2/4] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20=EB=8C=93?= =?UTF-8?q?=EA=B8=80=20ResponseDTO=20=EC=88=98=EC=A0=95,=20=EB=B9=84?= =?UTF-8?q?=EB=B0=80=20=EB=8C=93=EA=B8=80=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../board/controller/BoardController.java | 3 +-- .../dto/response/CommentResponseDTO.java | 22 +++++++++---------- .../queryService/CommentQueryServiceImpl.java | 5 ----- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/example/template/domain/board/controller/BoardController.java b/src/main/java/com/example/template/domain/board/controller/BoardController.java index 4c76fcf..78e1aa5 100644 --- a/src/main/java/com/example/template/domain/board/controller/BoardController.java +++ b/src/main/java/com/example/template/domain/board/controller/BoardController.java @@ -32,8 +32,6 @@ public class BoardController { private final BoardCommandService boardCommandService; // QueryService - // TODO : 내가 쓴 게시글 - // TODO : 내가 댓글 단 게시글 @Operation(summary = "게시글 목록 조회 (전체 및 카테고리별)", description = "커뮤니티 게시글 목록을 전체 또는 카테고리별로 무한 스크롤 방식으로 조회합니다..") @GetMapping public ApiResponse getBoardList( @@ -93,6 +91,7 @@ public ApiResponse uploadBoardImages( public ResponseEntity> createBoard( @Valid @RequestBody BoardRequestDTO.CreateBoardDTO createBoardDTO, @AuthenticatedMember Member member) { + // TODO: 어차피 게시글 목록 페이지로 리다이렉트 되어서, boardId만 Return 하는 방식 고려 return ResponseEntity .status(HttpStatus.CREATED) .body(ApiResponse.onSuccess(HttpStatus.CREATED, diff --git a/src/main/java/com/example/template/domain/board/dto/response/CommentResponseDTO.java b/src/main/java/com/example/template/domain/board/dto/response/CommentResponseDTO.java index 0d855bc..b7ed338 100644 --- a/src/main/java/com/example/template/domain/board/dto/response/CommentResponseDTO.java +++ b/src/main/java/com/example/template/domain/board/dto/response/CommentResponseDTO.java @@ -28,17 +28,13 @@ public static class CommentImgDTO { public static class CommentDTO { private Long id; private String content; - private boolean secret; private Long memberId; private String memberName; private LocalDateTime createdAt; private List images; - private boolean deleted; private Long parentId; // 현재 사용자가 댓글 작성자인지 여부 private boolean author; // true인 경우: 댓글 수정/삭제 옵션을 표시 - // 현재 사용자가 비밀 댓글을 볼 수 있는지 여부 (게시글 작성자 or 댓글본인) - private boolean canViewSecret; // true인 경우: 비밀 댓글의 실제 내용을 표시 private List replies; public static CommentDTO from(Comment comment, Member currentMember) { @@ -50,22 +46,17 @@ public static CommentDTO from(Comment comment, Member currentMember) { .id(comment.getId()) // 부모 댓글이 있는 경우 부모 댓글의 ID를 설정 .parentId(comment.getParent() != null ? comment.getParent().getId() : null) - .content(getCommentContent(comment, canViewSecret)).secret(comment.isSecret()) + .content(getCommentContent(comment, canViewSecret)) // 삭제된 댓글인 경우 작성자 ID를 null로 설정 .memberId(comment.isDeleted() ? null : comment.getMember().getId()) // 삭제된 댓글인 경우 작성자 이름을 "(삭제)"로 표시 .memberName(comment.isDeleted() ? DELETED_MEMBER_NAME : comment.getMember().getName()) .createdAt(comment.getCreatedAt()) // 삭제된 댓글인 경우 이미지 목록을 비움, 그렇지 않으면 이미지 URL 목록 생성 - .images(comment.isDeleted() ? Collections.emptyList() : - comment.getImages().stream().map(CommentImg::getCommentImgUrl).toList()) - .deleted(comment.isDeleted()) + .images(getCommentImages(comment, canViewSecret)) // 현재 사용자가 댓글 작성자이고 댓글이 삭제되지 않았을 경우 true .author(isCommentAuthor && !comment.isDeleted()) - // 비밀 댓글을 볼 수 있는 권한이 있고 댓글이 삭제되지 않았을 경우 true - .canViewSecret(canViewSecret && !comment.isDeleted()) - // comment.getChildren()이 null일 경우 빈 리스트를 반환하고, - // null이 아닐 경우 모든 자식 댓글을 CommentDTO로 변환 + // 대댓글 .replies(Optional.ofNullable(comment.getChildren()) .map(children -> children.stream() .map(childComment -> CommentDTO.from(childComment, currentMember)) @@ -96,6 +87,13 @@ private static String getCommentContent(Comment comment, boolean canViewSecret) } return comment.getContent(); } + + private static List getCommentImages(Comment comment, boolean canViewSecret) { + if (comment.isDeleted() || (comment.isSecret() && !canViewSecret)) { + return Collections.emptyList(); + } + return comment.getImages().stream().map(CommentImg::getCommentImgUrl).toList(); + } } @Getter diff --git a/src/main/java/com/example/template/domain/board/service/queryService/CommentQueryServiceImpl.java b/src/main/java/com/example/template/domain/board/service/queryService/CommentQueryServiceImpl.java index ba9d8ee..ebe52ce 100644 --- a/src/main/java/com/example/template/domain/board/service/queryService/CommentQueryServiceImpl.java +++ b/src/main/java/com/example/template/domain/board/service/queryService/CommentQueryServiceImpl.java @@ -1,11 +1,7 @@ package com.example.template.domain.board.service.queryService; import com.example.template.domain.board.dto.response.CommentResponseDTO; -import com.example.template.domain.board.entity.Board; import com.example.template.domain.board.entity.Comment; -import com.example.template.domain.board.exception.BoardErrorCode; -import com.example.template.domain.board.exception.BoardException; -import com.example.template.domain.board.repository.BoardRepository; import com.example.template.domain.board.repository.CommentRepository; import com.example.template.domain.member.entity.Member; import lombok.RequiredArgsConstructor; @@ -22,7 +18,6 @@ public class CommentQueryServiceImpl implements CommentQueryService { private final CommentRepository commentRepository; - private final BoardRepository boardRepository; @Override public CommentResponseDTO.CommentsListDTO getCommentsList(Long boardId, Member member) { From 20a4bfa40d7035ccd5909d650b949a0db25e3b18 Mon Sep 17 00:00:00 2001 From: jinho7 <69239293+jinho7@users.noreply.github.com> Date: Sat, 17 Aug 2024 20:06:28 +0900 Subject: [PATCH 3/4] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=EB=90=9C=20=EB=8C=93=EA=B8=80=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?=EC=8B=9C=EB=8F=84=ED=95=98=EB=8A=94=20=EA=B2=BD=EC=9A=B0=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../template/domain/board/exception/CommentErrorCode.java | 3 ++- .../service/commandService/CommentCommandServiceImpl.java | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/example/template/domain/board/exception/CommentErrorCode.java b/src/main/java/com/example/template/domain/board/exception/CommentErrorCode.java index 29b4754..850b324 100644 --- a/src/main/java/com/example/template/domain/board/exception/CommentErrorCode.java +++ b/src/main/java/com/example/template/domain/board/exception/CommentErrorCode.java @@ -14,7 +14,8 @@ public enum CommentErrorCode implements BaseErrorCode { COMMENT_BOARD_MISMATCH(HttpStatus.BAD_REQUEST, "COMMENT400", "댓글이 해당 게시글에 속하지 않습니다."), INVALID_IMAGE_URLS(HttpStatus.BAD_REQUEST, "COMMENT400", "일부 이미지 URL이 유효하지 않거나 찾을 수 없습니다."), PARENT_COMMENT_NOT_FOUND(HttpStatus.BAD_REQUEST, "COMMENT400", "부모 댓글을 찾을 수 없거나 해당 게시글에 속하지 않습니다."), - NESTED_REPLY_NOT_ALLOWED(HttpStatus.BAD_REQUEST, "COMMENT400", "대댓글에 대한 답글은 작성할 수 없습니다."); + NESTED_REPLY_NOT_ALLOWED(HttpStatus.BAD_REQUEST, "COMMENT400", "대댓글에 대한 답글은 작성할 수 없습니다."), + COMMENT_ALREADY_DELETED(HttpStatus.BAD_REQUEST,"COMMENT400","이미 삭제된 댓글은 수정할 수 없습니다."); private final HttpStatus httpStatus; private final String code; diff --git a/src/main/java/com/example/template/domain/board/service/commandService/CommentCommandServiceImpl.java b/src/main/java/com/example/template/domain/board/service/commandService/CommentCommandServiceImpl.java index 4046f52..51dab1d 100644 --- a/src/main/java/com/example/template/domain/board/service/commandService/CommentCommandServiceImpl.java +++ b/src/main/java/com/example/template/domain/board/service/commandService/CommentCommandServiceImpl.java @@ -132,6 +132,12 @@ public CommentResponseDTO.CommentDTO updateComment(Long boardId, Long commentId, .orElseThrow(() -> new CommentException(CommentErrorCode.COMMENT_NOT_FOUND)); validateCommentOwnership(comment, member); + // 삭제된 댓글 수정 시도 체크 + if (comment.isDeleted()) { + throw new CommentException(CommentErrorCode.COMMENT_ALREADY_DELETED); + } + + // 댓글이 해당 게시글에 속하지 않는 경우 if (!comment.getBoard().getId().equals(boardId)) { throw new CommentException(CommentErrorCode.COMMENT_BOARD_MISMATCH); } @@ -139,6 +145,7 @@ public CommentResponseDTO.CommentDTO updateComment(Long boardId, Long commentId, comment.setContent(updateDTO.getContent()); comment.setSecret(updateDTO.isSecret()); + // 이미지 처리 if (updateDTO.getImages() != null) { List currentImageUrls = comment.getImages().stream() .map(CommentImg::getCommentImgUrl) From 6ffee952d0ba1551a130b278b440af9fee348f2d Mon Sep 17 00:00:00 2001 From: jinho7 <69239293+jinho7@users.noreply.github.com> Date: Sat, 17 Aug 2024 20:07:02 +0900 Subject: [PATCH 4/4] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=EB=90=9C=20=EB=8C=93=EA=B8=80=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?=EC=8B=9C=EB=8F=84=ED=95=98=EB=8A=94=20=EA=B2=BD=EC=9A=B0=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/commandService/CommentCommandServiceImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/template/domain/board/service/commandService/CommentCommandServiceImpl.java b/src/main/java/com/example/template/domain/board/service/commandService/CommentCommandServiceImpl.java index 51dab1d..1236e91 100644 --- a/src/main/java/com/example/template/domain/board/service/commandService/CommentCommandServiceImpl.java +++ b/src/main/java/com/example/template/domain/board/service/commandService/CommentCommandServiceImpl.java @@ -130,13 +130,13 @@ public CommentResponseDTO.CommentDTO createComment(Long boardId, CommentRequestD public CommentResponseDTO.CommentDTO updateComment(Long boardId, Long commentId, CommentRequestDTO.UpdateDTO updateDTO, Member member) { Comment comment = commentRepository.findById(commentId) .orElseThrow(() -> new CommentException(CommentErrorCode.COMMENT_NOT_FOUND)); - validateCommentOwnership(comment, member); - // 삭제된 댓글 수정 시도 체크 if (comment.isDeleted()) { throw new CommentException(CommentErrorCode.COMMENT_ALREADY_DELETED); } + validateCommentOwnership(comment, member); + // 댓글이 해당 게시글에 속하지 않는 경우 if (!comment.getBoard().getId().equals(boardId)) { throw new CommentException(CommentErrorCode.COMMENT_BOARD_MISMATCH);