From 43c5ccaf0bec21624f750240bd6f5d1f2e367f00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=95=9C=EA=B4=80=ED=9D=AC?= <85067003+limehee@users.noreply.github.com> Date: Sun, 5 May 2024 18:31:36 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B2=8C=EC=8B=9C=EA=B8=80=20=EB=B0=8F=20?= =?UTF-8?q?=EB=8C=93=EA=B8=80=20=EB=B0=98=ED=99=98=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EC=99=84=EB=A3=8C=20(#335)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor(Comment): 댓글 생성, 삭제, 수정시 게시글의 id를 반환하도록 벼녁ㅇ * refactor(Comment): 댓글 생성, 삭제, 수정시 게시글의 id를 반환하도록 변경 * refactor(Comment): 댓글 응답 정보에 생성일자(createdAt) 추가 * refactor(Board): 게시글 생성, 수정, 삭제시 삭제된 게시글의 카테고리가 반환되도록 변경 --- .../clab/api/domain/board/api/BoardController.java | 12 ++++++------ .../api/domain/board/application/BoardService.java | 12 ++++++------ .../domain/comment/application/CommentService.java | 7 ++++--- .../comment/dto/response/CommentResponseDto.java | 1 + 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/main/java/page/clab/api/domain/board/api/BoardController.java b/src/main/java/page/clab/api/domain/board/api/BoardController.java index 1e633370f..5a99d0b35 100644 --- a/src/main/java/page/clab/api/domain/board/api/BoardController.java +++ b/src/main/java/page/clab/api/domain/board/api/BoardController.java @@ -41,10 +41,10 @@ public class BoardController { @Operation(summary = "[U] 커뮤니티 게시글 생성", description = "ROLE_USER 이상의 권한이 필요함") @Secured({"ROLE_USER", "ROLE_ADMIN", "ROLE_SUPER"}) @PostMapping("") - public ApiResponse createBoard( + public ApiResponse createBoard( @Valid @RequestBody BoardRequestDto requestDto ) throws PermissionDeniedException { - Long id = boardService.createBoard(requestDto); + String id = boardService.createBoard(requestDto); return ApiResponse.success(id); } @@ -98,21 +98,21 @@ public ApiResponse> getBoardsByCatego @PatchMapping("/{boardId}") @Operation(summary = "[U] 커뮤니티 게시글 수정", description = "ROLE_USER 이상의 권한이 필요함") @Secured({"ROLE_USER", "ROLE_ADMIN", "ROLE_SUPER"}) - public ApiResponse updateBoard( + public ApiResponse updateBoard( @PathVariable(name = "boardId") Long boardId, @Valid @RequestBody BoardUpdateRequestDto requestDto ) throws PermissionDeniedException { - Long id = boardService.updateBoard(boardId, requestDto); + String id = boardService.updateBoard(boardId, requestDto); return ApiResponse.success(id); } @DeleteMapping("/{boardId}") @Operation(summary = "[U] 커뮤니티 게시글 삭제", description = "ROLE_USER 이상의 권한이 필요함") @Secured({"ROLE_USER", "ROLE_ADMIN", "ROLE_SUPER"}) - public ApiResponse deleteBoard( + public ApiResponse deleteBoard( @PathVariable(name = "boardId") Long boardId ) throws PermissionDeniedException { - Long id = boardService.deleteBoard(boardId); + String id = boardService.deleteBoard(boardId); return ApiResponse.success(id); } diff --git a/src/main/java/page/clab/api/domain/board/application/BoardService.java b/src/main/java/page/clab/api/domain/board/application/BoardService.java index 143e111a0..32723d5b2 100644 --- a/src/main/java/page/clab/api/domain/board/application/BoardService.java +++ b/src/main/java/page/clab/api/domain/board/application/BoardService.java @@ -50,7 +50,7 @@ public class BoardService { private final CommentRepository commentRepository; @Transactional - public Long createBoard(BoardRequestDto requestDto) throws PermissionDeniedException { + public String createBoard(BoardRequestDto requestDto) throws PermissionDeniedException { Member currentMember = memberService.getCurrentMember(); List uploadedFiles = uploadedFileService.getUploadedFilesByUrls(requestDto.getFileUrlList()); Board board = BoardRequestDto.toEntity(requestDto, currentMember, uploadedFiles); @@ -59,7 +59,7 @@ public Long createBoard(BoardRequestDto requestDto) throws PermissionDeniedExcep if (board.shouldNotifyForNewBoard()) { notificationService.sendNotificationToMember(currentMember, "[" + board.getTitle() + "] 새로운 공지사항이 등록되었습니다."); } - return boardRepository.save(board).getId(); + return boardRepository.save(board).getCategory().getKey(); } @Transactional(readOnly = true) @@ -91,13 +91,13 @@ public PagedResponseDto getBoardsByCategory(BoardCateg } @Transactional - public Long updateBoard(Long boardId, BoardUpdateRequestDto requestDto) throws PermissionDeniedException { + public String updateBoard(Long boardId, BoardUpdateRequestDto requestDto) throws PermissionDeniedException { Member currentMember = memberService.getCurrentMember(); Board board = getBoardByIdOrThrow(boardId); board.validateAccessPermission(currentMember); board.update(requestDto); validationService.checkValid(board); - return boardRepository.save(board).getId(); + return boardRepository.save(board).getCategory().getKey(); } @Transactional @@ -123,12 +123,12 @@ public PagedResponseDto getDeletedBoards(Pageable pageable return new PagedResponseDto<>(boards.map(this::mapToBoardListResponseDto)); } - public Long deleteBoard(Long boardId) throws PermissionDeniedException { + public String deleteBoard(Long boardId) throws PermissionDeniedException { Member currentMember = memberService.getCurrentMember(); Board board = getBoardByIdOrThrow(boardId); board.validateAccessPermission(currentMember); boardRepository.delete(board); - return board.getId(); + return board.getCategory().getKey(); } @NotNull diff --git a/src/main/java/page/clab/api/domain/comment/application/CommentService.java b/src/main/java/page/clab/api/domain/comment/application/CommentService.java index 4ebfc21d8..59bb8acef 100644 --- a/src/main/java/page/clab/api/domain/comment/application/CommentService.java +++ b/src/main/java/page/clab/api/domain/comment/application/CommentService.java @@ -51,7 +51,7 @@ public class CommentService { public Long createComment(Long parentId, Long boardId, CommentRequestDto requestDto) { Comment comment = createAndStoreComment(parentId, boardId, requestDto); sendNotificationForNewComment(comment); - return comment.getId(); + return boardId; } @Transactional(readOnly = true) @@ -89,7 +89,8 @@ public Long updateComment(Long commentId, CommentUpdateRequestDto requestDto) th comment.validateAccessPermission(currentMember); comment.update(requestDto); validationService.checkValid(comment); - return commentRepository.save(comment).getId(); + commentRepository.save(comment); + return comment.getBoard().getId(); } public Long deleteComment(Long commentId) throws PermissionDeniedException { @@ -98,7 +99,7 @@ public Long deleteComment(Long commentId) throws PermissionDeniedException { comment.validateAccessPermission(currentMember); comment.updateIsDeleted(); commentRepository.save(comment); - return comment.getId(); + return comment.getBoard().getId(); } @Transactional diff --git a/src/main/java/page/clab/api/domain/comment/dto/response/CommentResponseDto.java b/src/main/java/page/clab/api/domain/comment/dto/response/CommentResponseDto.java index 1222caece..b11f029f5 100644 --- a/src/main/java/page/clab/api/domain/comment/dto/response/CommentResponseDto.java +++ b/src/main/java/page/clab/api/domain/comment/dto/response/CommentResponseDto.java @@ -47,6 +47,7 @@ public static CommentResponseDto toDto(Comment comment, String currentMemberId) .children(comment.getChildren().stream() .map(child -> CommentResponseDto.toDto(child, currentMemberId)) .toList()) + .createdAt(comment.getCreatedAt()) .build(); } return CommentResponseDto.builder()