숙련주차 개인과제
댓글 컨트롤러 단
@PostMapping("/write")
public CommentResponseDto createComment(@RequestBody @Valid CommentRequestDto requestDto, BindingResult bindingResult
,@CookieValue(JwtUtil.AUTHORIZATION_HEADER) String tokenValue) {
checkError(bindingResult);
if(!requestDto.getUsername().equals(getJwt(tokenValue))) {
throw new IllegalArgumentException("잘못된 username");
}
return commentService.createComment(requestDto);
}
@PutMapping("/update")
public CommentResponseDto updateComment(long commentId, @RequestBody @Valid CommentRequestDto requestDto, BindingResult bindingResult
,@CookieValue(JwtUtil.AUTHORIZATION_HEADER) String tokenValue)
{
if(commentId < 1) {
throw new IllegalArgumentException();
}
checkError(bindingResult);
if(!requestDto.getUsername().equals(getJwt(tokenValue))) {
throw new IllegalArgumentException("잘못된 username");
}
return commentService.updateComment(commentId, requestDto);
}
@DeleteMapping
public String deleteComment(long commentId, @RequestBody CommentRequestDto requestDto
,@CookieValue(JwtUtil.AUTHORIZATION_HEADER) String tokenValue) {
commentService.deleteComment(commentId, requestDto);
if(!requestDto.getUsername().equals(getJwt(tokenValue))) {
throw new IllegalArgumentException("잘못된 username");
}
ResponseEntity.status(201);
return "성공했습니다";
}
'TIL > Web Back' 카테고리의 다른 글
[Sparta] 내일배움캠프 TIL 31일차 (0) | 2024.06.04 |
---|---|
[Sparta] 내일배움캠프 TIL 30일차 (0) | 2024.06.03 |
[Sparta] 내일배움캠프 TIL 28일차 (0) | 2024.05.30 |
[Sparta] 내일배움캠프 TIL 27일차 (0) | 2024.05.29 |
[Sparta] 내일배움캠프 TIL 26일차 (0) | 2024.05.28 |