Skip to content

Commit

Permalink
refactor: comment API 버저닝 제거 #584 (#585)
Browse files Browse the repository at this point in the history
  • Loading branch information
linirini authored Jan 19, 2025
1 parent 5776e7f commit 8361895
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,8 @@ public ResponseEntity<CommentResponses> readCommentsByMomentId(
return ResponseEntity.ok().body(commentResponses);
}

@PutMapping
@PutMapping("/{commentId}")
public ResponseEntity<Void> updateComment(
@LoginMember Member member,
@RequestParam @Min(value = 1L, message = "댓글 식별자는 양수로 이루어져야 합니다.") long commentId,
@Valid @RequestBody CommentUpdateRequest commentUpdateRequest
) {
commentService.updateComment(member, commentId, commentUpdateRequest);
return ResponseEntity.ok().build();
}

@PutMapping("/v2/{commentId}")
public ResponseEntity<Void> updateCommentV2(
@LoginMember Member member,
@PathVariable @Min(value = 1L, message = "댓글 식별자는 양수로 이루어져야 합니다.") long commentId,
@Valid @RequestBody CommentUpdateRequest commentUpdateRequest
Expand All @@ -71,17 +61,8 @@ public ResponseEntity<Void> updateCommentV2(
return ResponseEntity.ok().build();
}

@DeleteMapping
@DeleteMapping("/{commentId}")
public ResponseEntity<Void> deleteComment(
@RequestParam @Min(value = 1L, message = "댓글 식별자는 양수로 이루어져야 합니다.") long commentId,
@LoginMember Member member
) {
commentService.deleteComment(commentId, member);
return ResponseEntity.ok().build();
}

@DeleteMapping("/v2/{commentId}")
public ResponseEntity<Void> deleteCommentV2(
@PathVariable @Min(value = 1L, message = "댓글 식별자는 양수로 이루어져야 합니다.") long commentId,
@LoginMember Member member
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,28 +62,7 @@ ResponseEntity<CommentResponses> readCommentsByMomentId(
""",
responseCode = "400")
})
ResponseEntity<Void> updateComment(
@Parameter(hidden = true) Member member,
@Parameter(description = "댓글 식별자", example = "1") @Min(value = 1L, message = "댓글 식별자는 양수로 이루어져야 합니다.") long commentId,
@Parameter(description = "댓글 수정 시 요구 형식") @Valid CommentUpdateRequest commentUpdateRequest);

@Operation(summary = "댓글 수정", description = "댓글을 수정합니다.")
@ApiResponses(value = {
@ApiResponse(description = "댓글 수정 성공", responseCode = "200"),
@ApiResponse(description = """
<발생 가능한 케이스>
(1) 댓글 식별자가 양수가 아닐 때
(2) 요청한 댓글을 찾을 수 없을 때
(3) 댓글 내용이 공백 뿐이거나 없을 때
(4) 댓글이 공백 포함 500자 초과일 때
""",
responseCode = "400")
})
public ResponseEntity<Void> updateCommentV2(
public ResponseEntity<Void> updateComment(
@Parameter(hidden = true) Member member,
@Parameter(description = "댓글 식별자", example = "1") @Min(value = 1L, message = "댓글 식별자는 양수로 이루어져야 합니다.") long commentId,
@Parameter(description = "댓글 수정 시 요구 형식") @Valid CommentUpdateRequest commentUpdateRequest
Expand All @@ -94,16 +73,7 @@ public ResponseEntity<Void> updateCommentV2(
@ApiResponse(description = "댓글 삭제 성공", responseCode = "200"),
@ApiResponse(description = "댓글 식별자가 양수가 아닐 시 댓글 삭제 실패", responseCode = "400")
})
ResponseEntity<Void> deleteComment(
@Parameter(description = "댓글 식별자", example = "1") @Min(value = 1L, message = "댓글 식별자는 양수로 이루어져야 합니다.") long commentId,
@Parameter(hidden = true) Member member);

@Operation(summary = "댓글 삭제", description = "댓글을 삭제합니다.")
@ApiResponses(value = {
@ApiResponse(description = "댓글 삭제 성공", responseCode = "200"),
@ApiResponse(description = "댓글 식별자가 양수가 아닐 시 댓글 삭제 실패", responseCode = "400")
})
public ResponseEntity<Void> deleteCommentV2(
public ResponseEntity<Void> deleteComment(
@Parameter(description = "댓글 식별자", example = "1") @Min(value = 1L, message = "댓글 식별자는 양수로 이루어져야 합니다.") long commentId,
@Parameter(hidden = true) Member member
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,7 @@ void updateComment() throws Exception {
""";

// when & then
mockMvc.perform(put("/comments")
.param("commentId", "1")
.content(commentUpdateRequest)
.contentType(MediaType.APPLICATION_JSON)
.header(HttpHeaders.AUTHORIZATION, "token"))
.andExpect(status().isOk());

mockMvc.perform(put("/comments/v2/{commentId}", 1)
mockMvc.perform(put("/comments/{commentId}", 1)
.content(commentUpdateRequest)
.contentType(MediaType.APPLICATION_JSON)
.header(HttpHeaders.AUTHORIZATION, "token"))
Expand All @@ -185,8 +178,7 @@ void updateCommentFail() throws Exception {
ExceptionResponse exceptionResponse = new ExceptionResponse(HttpStatus.BAD_REQUEST.toString(), "댓글 식별자는 양수로 이루어져야 합니다.");

// when & then
mockMvc.perform(put("/comments")
.param("commentId", "0")
mockMvc.perform(put("/comments/{commentId}", 0)
.content(objectMapper.writeValueAsString(commentUpdateRequest))
.contentType(MediaType.APPLICATION_JSON)
.header(HttpHeaders.AUTHORIZATION, "token"))
Expand All @@ -205,8 +197,7 @@ void updateCommentFailByBlank(String updatedContent) throws Exception {
ExceptionResponse exceptionResponse = new ExceptionResponse(HttpStatus.BAD_REQUEST.toString(), "댓글 내용을 입력해주세요.");

// when & then
mockMvc.perform(put("/comments")
.param("commentId", "1")
mockMvc.perform(put("/comments/{commentId}", 1)
.content(objectMapper.writeValueAsString(commentUpdateRequest))
.contentType(MediaType.APPLICATION_JSON)
.header(HttpHeaders.AUTHORIZATION, "token"))
Expand All @@ -221,13 +212,7 @@ void deleteComment() throws Exception {
when(authService.extractFromToken(any())).thenReturn(MemberFixture.create());

// when & then
mockMvc.perform(delete("/comments")
.param("commentId", "1")
.contentType(MediaType.APPLICATION_JSON)
.header(HttpHeaders.AUTHORIZATION, "token"))
.andExpect(status().isOk());

mockMvc.perform(delete("/comments/v2/{commentId}", 1)
mockMvc.perform(delete("/comments/{commentId}", 1)
.contentType(MediaType.APPLICATION_JSON)
.header(HttpHeaders.AUTHORIZATION, "token"))
.andExpect(status().isOk());
Expand All @@ -241,8 +226,7 @@ void deleteCommentFail() throws Exception {
ExceptionResponse exceptionResponse = new ExceptionResponse(HttpStatus.BAD_REQUEST.toString(), "댓글 식별자는 양수로 이루어져야 합니다.");

// when & then
mockMvc.perform(delete("/comments")
.param("commentId", "0")
mockMvc.perform(delete("/comments/{commentId}", 0)
.contentType(MediaType.APPLICATION_JSON)
.header(HttpHeaders.AUTHORIZATION, "token"))
.andExpect(status().isBadRequest())
Expand Down

0 comments on commit 8361895

Please sign in to comment.