Skip to content

Commit d7c1241

Browse files
committed
[Feat]: 응답 형태 변경
1 parent ddbad1d commit d7c1241

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

back/src/main/java/com/back/domain/post/controller/PostController.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.back.domain.post.dto.PostRequest;
44
import com.back.domain.post.dto.PostResponse;
55
import com.back.domain.post.service.PostService;
6+
import com.back.global.common.ApiResponse;
67
import jakarta.validation.Valid;
78
import lombok.RequiredArgsConstructor;
89
import org.springframework.http.HttpStatus;
@@ -23,38 +24,38 @@ public class PostController {
2324

2425
// 게시글 생성
2526
@PostMapping
26-
public ResponseEntity<PostResponse> createPost(
27+
public ApiResponse<PostResponse> createPost(
2728
@RequestBody @Valid PostRequest request) {
2829
Long userId = 1L; // fixme 임시 사용자 ID
2930
PostResponse response = postService.createPost(userId, request);
30-
return ResponseEntity.status(HttpStatus.CREATED).body(response);
31+
return ApiResponse.success(response, "성공적으로 생성되었습니다.", HttpStatus.CREATED);
3132
}
3233

3334
// 게시글 목록 조회
3435
@GetMapping
35-
public ResponseEntity<List<PostResponse>> getPosts() {
36+
public ApiResponse<List<PostResponse>> getPosts() {
3637
List<PostResponse> responses = postService.getPosts();
37-
return ResponseEntity.ok(responses);
38+
return ApiResponse.success(responses, "성공적으로 조회되었습니다.", HttpStatus.OK);
3839
}
3940

4041
// 게시글 단건 조회
4142
@GetMapping("/{postId}")
42-
public ResponseEntity<PostResponse> getPost(@PathVariable Long postId) {
43-
return ResponseEntity.ok(postService.getPost(postId));
43+
public ApiResponse<PostResponse> getPost(@PathVariable Long postId) {
44+
return ApiResponse.success(postService.getPost(postId), "성공적으로 조회되었습니다.", HttpStatus.OK);
4445
}
4546

4647
@PutMapping("/{postId}")
47-
public ResponseEntity<PostResponse> updatePost(
48+
public ApiResponse<PostResponse> updatePost(
4849
@PathVariable Long postId,
4950
@RequestBody @Valid PostRequest request) {
5051
Long userId = 1L; // fixme 임시 사용자 ID
51-
return ResponseEntity.ok(postService.updatePost(userId, postId, request));
52+
return ApiResponse.success(postService.updatePost(userId, postId, request), "성공적으로 수정되었습니다.", HttpStatus.OK);
5253
}
5354

5455
@DeleteMapping("/{postId}")
55-
public ResponseEntity<Void> deletePost(@PathVariable Long postId) {
56+
public ApiResponse<Void> deletePost(@PathVariable Long postId) {
5657
Long userId = 1L; // fixme 임시 사용자 ID
5758
postService.deletePost(userId, postId);
58-
return ResponseEntity.ok().build();
59+
return ApiResponse.success(null, "성공적으로 삭제되었습니다.", HttpStatus.OK);
5960
}
6061
}

0 commit comments

Comments
 (0)