From 208bd69d5bcf16a99049fa6204a1179c758cd83e Mon Sep 17 00:00:00 2001 From: yulmam <70622601+yulmam@users.noreply.github.com> Date: Wed, 7 Aug 2024 11:08:26 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20=EA=B2=8C=EC=8B=9C=ED=8C=90=20?= =?UTF-8?q?=EB=8C=93=EA=B8=80=20=EC=9E=91=EC=84=B1=EC=9E=90=20=EC=B2=B4?= =?UTF-8?q?=ED=81=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../board/controller/BoardController.java | 19 +++++++++++++------ .../entity/dto/ResponseBoardDetailDto.java | 2 +- .../board/entity/dto/ResponseCommentDto.java | 1 + .../edufocus/board/entity/vo/Board.java | 4 ++-- .../edufocus/board/entity/vo/Comment.java | 3 ++- .../edufocus/board/service/BoardService.java | 4 ++-- .../board/service/BoardServiceImpl.java | 8 ++++---- 7 files changed, 25 insertions(+), 16 deletions(-) diff --git a/backend/src/main/java/com/edufocus/edufocus/board/controller/BoardController.java b/backend/src/main/java/com/edufocus/edufocus/board/controller/BoardController.java index 5bd154d..309acb6 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/controller/BoardController.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/controller/BoardController.java @@ -45,9 +45,13 @@ public class BoardController { @GetMapping(value = "/{boardId}") public ResponseEntity getBoardDetail( - @PathVariable int boardId + @PathVariable int boardId, + HttpServletRequest request ){ - ResponseBoardDetailDto responseBoardDetailDto = boardService.findBoardDetail(boardId); + String token = request.getHeader("Authorization"); + long userId = Long.parseLong(jwtUtil.getUserId(token)); + + ResponseBoardDetailDto responseBoardDetailDto = boardService.findBoardDetail(userId, boardId); return new ResponseEntity<>(responseBoardDetailDto, HttpStatus.OK); } @@ -77,8 +81,7 @@ public class BoardController { @DeleteMapping(value = "/{boardId}") public ResponseEntity deleteBoard( - @PathVariable int boardId, - HttpServletRequest request + @PathVariable int boardId ){ boardService.deleteBoard(boardId); @@ -87,9 +90,13 @@ public class BoardController { @GetMapping(value = "/comment/{boardId}") public ResponseEntity> getComments( - @PathVariable int boardId + @PathVariable int boardId, + HttpServletRequest request ){ - List comments = boardService.findComments(boardId); + String token = request.getHeader("Authorization"); + long userId = Long.parseLong(jwtUtil.getUserId(token)); + + List comments = boardService.findComments(userId, boardId); return new ResponseEntity<>(comments, HttpStatus.OK); } diff --git a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardDetailDto.java b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardDetailDto.java index e050da7..7a6e8fe 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardDetailDto.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseBoardDetailDto.java @@ -16,7 +16,7 @@ public class ResponseBoardDetailDto { private String name; private String title; private String content; - private int viewCount; + private boolean isMine; private LocalDateTime createdAt; private LocalDateTime modifiedAt; } diff --git a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseCommentDto.java b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseCommentDto.java index 180c6b1..2e0ec6e 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseCommentDto.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/entity/dto/ResponseCommentDto.java @@ -14,6 +14,7 @@ public class ResponseCommentDto { private long id; private String name; private String content; + private boolean isMine; private LocalDateTime createAt; private LocalDateTime modifiedAt; } diff --git a/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Board.java b/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Board.java index ff8d039..e1e4ac6 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Board.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Board.java @@ -67,13 +67,13 @@ public class Board { .build(); } - public ResponseBoardDetailDto makeDetailDto(){ + public ResponseBoardDetailDto makeDetailDto(long userId){ return ResponseBoardDetailDto.builder() .id(id) .name(user.getName()) .title(title) .content(content) - .viewCount(viewCount) + .isMine(user.getId() == userId) .createdAt(createdAt) .modifiedAt(modifiedAt) .build(); diff --git a/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Comment.java b/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Comment.java index d7c97c2..aa05c5b 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Comment.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Comment.java @@ -39,11 +39,12 @@ public class Comment { @JoinColumn(name = "board_id") Board board; - public ResponseCommentDto makeCommentDto() { + public ResponseCommentDto makeCommentDto(long userId) { return ResponseCommentDto.builder() .id(id) .name(user.getName()) .content(content) + .isMine(user.getId() == userId) .createAt(createdAt) .modifiedAt(modifiedAt) .build(); diff --git a/backend/src/main/java/com/edufocus/edufocus/board/service/BoardService.java b/backend/src/main/java/com/edufocus/edufocus/board/service/BoardService.java index f0d25f8..d5c646d 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/service/BoardService.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/service/BoardService.java @@ -10,7 +10,7 @@ public interface BoardService { public List findBoards(int pageNo, String category, long lectureId); - public ResponseBoardDetailDto findBoardDetail(long boardId); + public ResponseBoardDetailDto findBoardDetail(long userId, long boardId); public void updateBoard(long boardId, RequestBoardUpdateDto requestBoardUpdateDto); @@ -18,7 +18,7 @@ public interface BoardService { public void createComment(long userId, long boardId, RequestCommentDto requestCommentDto); - public List findComments(long boardId); + public List findComments(long userId, long boardId); public void updateComment(long commentId, RequestCommentDto requestCommentDto); diff --git a/backend/src/main/java/com/edufocus/edufocus/board/service/BoardServiceImpl.java b/backend/src/main/java/com/edufocus/edufocus/board/service/BoardServiceImpl.java index f471fed..3fc7250 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/service/BoardServiceImpl.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/service/BoardServiceImpl.java @@ -48,10 +48,10 @@ public class BoardServiceImpl implements BoardService { } @Transactional - public ResponseBoardDetailDto findBoardDetail(long boardId) { + public ResponseBoardDetailDto findBoardDetail(long userId, long boardId) { return boardRepository.findById(boardId) .orElseThrow(NoSuchElementException::new) - .makeDetailDto(); + .makeDetailDto(userId); } @Transactional @@ -89,9 +89,9 @@ public class BoardServiceImpl implements BoardService { } @Transactional - public List findComments(long boardId) { + public List findComments(long userId, long boardId) { return commentRepository.findByBoardId(boardId).stream() - .map(Comment::makeCommentDto) + .map((Comment c) -> c.makeCommentDto(userId)) .collect(Collectors.toList()); }