Skip to content

Commit

Permalink
refactor: comments api uri 수정 #544 (#549)
Browse files Browse the repository at this point in the history
* feat: comment uri 변경 및 버저닝

* refactor: 불필요한 코드 변경을 최소화하기 위해 uri 상에서 버저닝 위치 변경
  • Loading branch information
linirini authored Nov 13, 2024
1 parent df2e70f commit 8de620e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
package com.staccato.comment.controller;

import java.net.URI;

import jakarta.validation.Valid;
import jakarta.validation.constraints.Min;

import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.staccato.comment.controller.docs.CommentControllerDocs;
import com.staccato.comment.service.CommentService;
import com.staccato.comment.service.dto.request.CommentRequest;
Expand All @@ -24,7 +22,6 @@
import com.staccato.config.auth.LoginMember;
import com.staccato.config.log.annotation.Trace;
import com.staccato.member.domain.Member;

import lombok.RequiredArgsConstructor;

@Trace
Expand Down Expand Up @@ -64,6 +61,16 @@ public ResponseEntity<Void> updateComment(
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
) {
commentService.updateComment(member, commentId, commentUpdateRequest);
return ResponseEntity.ok().build();
}

@DeleteMapping
public ResponseEntity<Void> deleteComment(
@RequestParam @Min(value = 1L, message = "댓글 식별자는 양수로 이루어져야 합니다.") long commentId,
Expand All @@ -72,4 +79,13 @@ public ResponseEntity<Void> deleteComment(
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
) {
commentService.deleteComment(commentId, member);
return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@

import jakarta.validation.Valid;
import jakarta.validation.constraints.Min;

import org.springframework.http.ResponseEntity;

import com.staccato.comment.service.dto.request.CommentRequest;
import com.staccato.comment.service.dto.request.CommentUpdateRequest;
import com.staccato.comment.service.dto.response.CommentResponses;
import com.staccato.member.domain.Member;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
Expand Down Expand Up @@ -70,6 +67,28 @@ ResponseEntity<Void> updateComment(
@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(
@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"),
Expand All @@ -78,4 +97,14 @@ ResponseEntity<Void> updateComment(
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(
@Parameter(description = "댓글 식별자", example = "1") @Min(value = 1L, message = "댓글 식별자는 양수로 이루어져야 합니다.") long commentId,
@Parameter(hidden = true) Member member
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ void updateComment() throws Exception {
.contentType(MediaType.APPLICATION_JSON)
.header(HttpHeaders.AUTHORIZATION, "token"))
.andExpect(status().isOk());

mockMvc.perform(put("/comments/v2/{commentId}", 1)
.content(commentUpdateRequest)
.contentType(MediaType.APPLICATION_JSON)
.header(HttpHeaders.AUTHORIZATION, "token"))
.andExpect(status().isOk());
}

@DisplayName("댓글 식별자가 양수가 아닐 경우 댓글 수정에 실패한다.")
Expand Down Expand Up @@ -236,6 +242,11 @@ void deleteComment() throws Exception {
.contentType(MediaType.APPLICATION_JSON)
.header(HttpHeaders.AUTHORIZATION, "token"))
.andExpect(status().isOk());

mockMvc.perform(delete("/comments/v2/{commentId}", 1)
.contentType(MediaType.APPLICATION_JSON)
.header(HttpHeaders.AUTHORIZATION, "token"))
.andExpect(status().isOk());
}

@DisplayName("댓글 식별자가 양수가 아닐 경우 댓글 삭제에 실패한다.")
Expand Down

0 comments on commit 8de620e

Please sign in to comment.