Skip to content

Commit

Permalink
게시글 및 댓글 반환 정보 수정 완료 (#335)
Browse files Browse the repository at this point in the history
* refactor(Comment): 댓글 생성, 삭제, 수정시 게시글의 id를 반환하도록 벼녁ㅇ

* refactor(Comment): 댓글 생성, 삭제, 수정시 게시글의 id를 반환하도록 변경

* refactor(Comment): 댓글 응답 정보에 생성일자(createdAt) 추가

* refactor(Board): 게시글 생성, 수정, 삭제시 삭제된 게시글의 카테고리가 반환되도록 변경
  • Loading branch information
limehee authored May 5, 2024
1 parent a47374c commit 43c5cca
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public class BoardController {
@Operation(summary = "[U] 커뮤니티 게시글 생성", description = "ROLE_USER 이상의 권한이 필요함")
@Secured({"ROLE_USER", "ROLE_ADMIN", "ROLE_SUPER"})
@PostMapping("")
public ApiResponse<Long> createBoard(
public ApiResponse<String> createBoard(
@Valid @RequestBody BoardRequestDto requestDto
) throws PermissionDeniedException {
Long id = boardService.createBoard(requestDto);
String id = boardService.createBoard(requestDto);
return ApiResponse.success(id);
}

Expand Down Expand Up @@ -98,21 +98,21 @@ public ApiResponse<PagedResponseDto<BoardCategoryResponseDto>> getBoardsByCatego
@PatchMapping("/{boardId}")
@Operation(summary = "[U] 커뮤니티 게시글 수정", description = "ROLE_USER 이상의 권한이 필요함")
@Secured({"ROLE_USER", "ROLE_ADMIN", "ROLE_SUPER"})
public ApiResponse<Long> updateBoard(
public ApiResponse<String> 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<Long> deleteBoard(
public ApiResponse<String> deleteBoard(
@PathVariable(name = "boardId") Long boardId
) throws PermissionDeniedException {
Long id = boardService.deleteBoard(boardId);
String id = boardService.deleteBoard(boardId);
return ApiResponse.success(id);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<UploadedFile> uploadedFiles = uploadedFileService.getUploadedFilesByUrls(requestDto.getFileUrlList());
Board board = BoardRequestDto.toEntity(requestDto, currentMember, uploadedFiles);
Expand All @@ -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)
Expand Down Expand Up @@ -91,13 +91,13 @@ public PagedResponseDto<BoardCategoryResponseDto> 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
Expand All @@ -123,12 +123,12 @@ public PagedResponseDto<BoardListResponseDto> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 43c5cca

Please sign in to comment.