Skip to content

Commit

Permalink
Chore: uri 변경 및 controller 이름 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
resource777 committed Nov 3, 2023
1 parent 4f6ce0c commit d007b61
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
@Slf4j
@RequiredArgsConstructor
@RestController
public class BoardApiController {
public class BoardController {
private final BoardService boardService;
private final MemberService memberService;
@Operation(description = "특정 캐릭터 게시판 게시글 작성")
@PostMapping("/api/boards/{characterId}")
@PostMapping("/boards/{characterId}")
public ResponseEntity<Board> addBoard(@PathVariable Long characterId,
@RequestBody AddBoardRequest request,
@Login Claims claims) {
Expand All @@ -46,7 +46,7 @@ public ResponseEntity<Board> addBoard(@PathVariable Long characterId,
}

@Operation(description = "특정 캐릭터 게시판 모든 게시글 조회")
@GetMapping("/api/boards/{characterId}")
@GetMapping("/boards/{characterId}")
public ResponseEntity<List<BoardResponse>> findAllBoards(@PathVariable Long characterId) {
List<BoardResponse> articles = boardService.findAllByCharacterId(characterId)
.stream()
Expand All @@ -58,42 +58,42 @@ public ResponseEntity<List<BoardResponse>> findAllBoards(@PathVariable Long char
}

@Operation(description = "특정 캐릭터 게시판 특정 게시글 조회")
@GetMapping("/api/boards/{characterId}/{id}")
public ResponseEntity<BoardResponse> findBoard(@PathVariable long id) {
Board article = boardService.findById(id);
@GetMapping("/boards/{characterId}/{postId}")
public ResponseEntity<BoardResponse> findBoard(@PathVariable long postId) {
Board article = boardService.findById(postId);

return ResponseEntity.ok()
.body(new BoardResponse(article));
}

@Operation(description = "특정 캐릭터 게시판 특정 게시글 삭제")
@DeleteMapping("/api/boards/{characterId}/{id}")
public ResponseEntity<Void> deleteBoard(@PathVariable long id, @Login Claims claims) {
@DeleteMapping("/boards/{characterId}/{postId}")
public ResponseEntity<Void> deleteBoard(@PathVariable long postId, @Login Claims claims) {
Long userId = claims.get("userId", Long.class);
if (!boardService.findById(id).getWriterId().equals(userId)) {
if (!boardService.findById(postId).getWriterId().equals(userId)) {
log.error("작성자가 아닌 글 삭제 요청");
return ResponseEntity.badRequest()
.build();
}
boardService.delete(id);
boardService.delete(postId);
return ResponseEntity.ok()
.build();
}

@Operation(description = "특정 캐릭터 게시판 특정 게시글 수정")
@PutMapping("/api/boards/{characterId}/{id}")
@PutMapping("/boards/{characterId}/{postId}")
public ResponseEntity<Board> updateBoard(
@PathVariable long id,
@PathVariable long postId,
@RequestBody UpdateBoardRequest request,
@Login Claims claims
) {
Long userId = claims.get("userId", Long.class);
if (!boardService.findById(id).getWriterId().equals(userId)) {
if (!boardService.findById(postId).getWriterId().equals(userId)) {
log.error("작성자가 아닌 글 수정 요청");
return ResponseEntity.badRequest()
.build();
}
Board updateArticle = boardService.update(id, request);
Board updateArticle = boardService.update(postId, request);

return ResponseEntity.ok()
.body(updateArticle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/characters")
@RequestMapping("/characters")
public class CharacterController {

private final CharacterService characterService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@

@Slf4j
@RequiredArgsConstructor
@RequestMapping("/api")
@RequestMapping("/comments")
@RestController
public class CommentApiController {
public class CommentController {
private final CommentService commentService;
private final MemberService memberService;

@PostMapping("/boards/{characterId}/{articleId}/comments")
@PostMapping("/{postId}")
public ResponseEntity commentSave(
@PathVariable Long articleId, @RequestBody CommentRequestDto dto, @Login Claims claims) {
@PathVariable Long postId, @RequestBody CommentRequestDto dto, @Login Claims claims) {
Long userId = claims.get("userId", Long.class);
return ResponseEntity.ok(commentService.commentSave(userId, articleId, dto));
return ResponseEntity.ok(commentService.commentSave(userId, postId, dto));
}

@GetMapping("/boards/{characterId}/{articleId}/comments")
@GetMapping("/{postId}")
public ResponseEntity<List<CommentResponseDto>> getComments(@PathVariable Long articleId) {
List<CommentResponseDto> comments = commentService.getCommentsByArticleId(articleId)
.stream()
Expand All @@ -49,7 +49,7 @@ public ResponseEntity<List<CommentResponseDto>> getComments(@PathVariable Long a
return ResponseEntity.ok(comments);
}

@PutMapping("/boards/{characterId}/{articleId}/comments/{commentId}")
@PutMapping("/{postId}/{commentId}")
public ResponseEntity<Long> updateComment(
@PathVariable Long commentId, @RequestBody CommentUpdateDto dto, @Login Claims claims) {
Long userId = claims.get("userId", Long.class);
Expand All @@ -62,16 +62,16 @@ public ResponseEntity<Long> updateComment(
return ResponseEntity.ok(updatedCommentId);
}

@DeleteMapping("/boards/{characterId}/{articleId}/comments/{commentId}")
@DeleteMapping("/{postId}/{commentId}")
public ResponseEntity<Void> deleteComment(
@PathVariable Long commentId, @PathVariable Long articleId, @Login Claims claims) {
@PathVariable Long commentId, @PathVariable Long postId, @Login Claims claims) {
Long userId = claims.get("userId", Long.class);
if (!commentService.findById(commentId).getMember().getId().equals(userId)) {
log.error("댓글 작성자가 아닌 댓글 삭제 요청");
return ResponseEntity.badRequest()
.build();
}
commentService.deleteComment(articleId, commentId);
commentService.deleteComment(postId, commentId);
return ResponseEntity.noContent().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
import lombok.RequiredArgsConstructor;

@RestController
@RequestMapping("/api/likes")
@RequestMapping("/likes")
@RequiredArgsConstructor
public class LikeController {

private final LikeService likeService;
private final MemberService memberService;

@PostMapping("/{boardId}")
public ResponseEntity addLike(@PathVariable("boardId")@Positive Long boardId, @Login Claims claims) {
@PostMapping("/{postId}")
public ResponseEntity addLike(@PathVariable("postId")@Positive Long postId, @Login Claims claims) {
Long userId = claims.get("userId", Long.class);
Member member = memberService.findByMemberId(userId);
likeService.addLike(boardId, member);
likeService.addLike(postId, member);
return ResponseEntity.status(HttpStatus.CREATED).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/friends")
@RequestMapping("/friends")
public class FriendshipController {

private final FriendshipService friendshipService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public ResponseEntity logout(HttpServletRequest request, @Login Claims claims) {
3. AccessToken을 발급하여 기존 RefreshToken과 함께 응답한다.
*/
@Operation(description = "access token 재발급")
@PostMapping("/refreshToken")
@PostMapping("/refreshtoken")
public ResponseEntity<MemberLoginResponseDto> requestRefresh(@RequestBody RefreshTokenDto refreshTokenDto) {
RefreshToken refreshToken = refreshTokenService.findRefreshToken(
refreshTokenDto.getRefreshToken()).orElseThrow(() ->
Expand Down

0 comments on commit d007b61

Please sign in to comment.