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()); }