Merge branch 'backend' of https://lab.ssafy.com/s11-webmobile1-sub2/S11P12A701 into be/email
This commit is contained in:
commit
779538d2e8
@ -45,9 +45,13 @@ public class BoardController {
|
||||
|
||||
@GetMapping(value = "/{boardId}")
|
||||
public ResponseEntity<ResponseBoardDetailDto> 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<List<ResponseCommentDto>> getComments(
|
||||
@PathVariable int boardId
|
||||
@PathVariable int boardId,
|
||||
HttpServletRequest request
|
||||
){
|
||||
List<ResponseCommentDto> comments = boardService.findComments(boardId);
|
||||
String token = request.getHeader("Authorization");
|
||||
long userId = Long.parseLong(jwtUtil.getUserId(token));
|
||||
|
||||
List<ResponseCommentDto> comments = boardService.findComments(userId, boardId);
|
||||
|
||||
return new ResponseEntity<>(comments, HttpStatus.OK);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -10,7 +10,7 @@ public interface BoardService {
|
||||
|
||||
public List<ResponseBoardSummaryDto> 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<ResponseCommentDto> findComments(long boardId);
|
||||
public List<ResponseCommentDto> findComments(long userId, long boardId);
|
||||
|
||||
public void updateComment(long commentId, RequestCommentDto requestCommentDto);
|
||||
|
||||
|
@ -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<ResponseCommentDto> findComments(long boardId) {
|
||||
public List<ResponseCommentDto> findComments(long userId, long boardId) {
|
||||
return commentRepository.findByBoardId(boardId).stream()
|
||||
.map(Comment::makeCommentDto)
|
||||
.map((Comment c) -> c.makeCommentDto(userId))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user