22
33import com .back .domain .comment .dto .CommentRequest ;
44import com .back .domain .comment .dto .CommentResponse ;
5+ import com .back .domain .comment .enums .CommentSortType ;
56import com .back .domain .comment .service .CommentService ;
6- import com .back .domain .post .dto .PostDetailResponse ;
7- import com .back .domain .post .dto .PostRequest ;
8- import com .back .domain .post .service .PostService ;
7+ import com .back .domain .post .dto .PostSummaryResponse ;
98import com .back .global .common .ApiResponse ;
9+ import com .back .global .common .PageResponse ;
1010import io .swagger .v3 .oas .annotations .Operation ;
1111import io .swagger .v3 .oas .annotations .Parameter ;
1212import io .swagger .v3 .oas .annotations .tags .Tag ;
1313import jakarta .validation .Valid ;
1414import lombok .RequiredArgsConstructor ;
15+ import org .springframework .data .domain .Page ;
16+ import org .springframework .data .domain .PageRequest ;
17+ import org .springframework .data .domain .Pageable ;
18+ import org .springframework .data .domain .Sort ;
1519import org .springframework .http .HttpStatus ;
1620import org .springframework .web .bind .annotation .*;
1721
@@ -41,4 +45,56 @@ public ApiResponse<CommentResponse> createPost(
4145 return ApiResponse .success (response , "성공적으로 생성되었습니다." , HttpStatus .OK );
4246 }
4347
48+ // 게시글 목록 조회
49+ @ GetMapping
50+ @ Operation (summary = "댓글 목록 조회" , description = "게시글 목록을 조회합니다." )
51+ public ApiResponse <PageResponse <CommentResponse >> getPosts (
52+ @ Parameter (description = "페이지 정보" ) Pageable pageable ,
53+ @ Parameter (description = "조회할 게시글 ID" , required = true ) @ PathVariable ("postId" ) Long postId ,
54+ @ Parameter (description = "정렬 조건 LATEST or LIKES" ) @ RequestParam (defaultValue = "LATEST" ) CommentSortType sortType ,
55+ @ RequestParam Long userId ) {
56+
57+ Sort sort = Sort .by (Sort .Direction .DESC , sortType .getProperty ());
58+
59+ Pageable sortedPageable = PageRequest .of (
60+ pageable .getPageNumber (),
61+ pageable .getPageSize (),
62+ sort
63+ );
64+
65+ Page <CommentResponse > responses = commentService .getComments (userId , postId , sortedPageable );
66+ return ApiResponse .success (PageResponse .of (responses ), "성공적으로 조회되었습니다." , HttpStatus .OK );
67+ }
68+
69+ // // 게시글 단건 조회
70+ // @GetMapping("/{postId}")
71+ // @Operation(summary = "게시글 상세 조회", description = "게시글 ID로 게시글을 조회합니다.")
72+ // public ApiResponse<PostDetailResponse> getPost(
73+ // @Parameter(description = "조회할 게시글 ID", required = true) @PathVariable Long postId,
74+ // @RequestParam Long userId) {
75+ // return ApiResponse.success(postService.getPost(userId, postId), "성공적으로 조회되었습니다.", HttpStatus.OK);
76+ // }
77+ //
78+ // @PutMapping("/{postId}")
79+ // @Operation(summary = "게시글 수정", description = "게시글 ID로 게시글을 수정합니다.")
80+ // public ApiResponse<Long> updatePost(
81+ // @Parameter(description = "수정할 게시글 ID", required = true) @PathVariable Long postId,
82+ // @io.swagger.v3.oas.annotations.parameters.RequestBody(
83+ // description = "수정할 게시글 정보",
84+ // required = true
85+ // )
86+ // @RequestBody @Valid PostRequest request,
87+ // @RequestParam Long userId) {
88+ // return ApiResponse.success(postService.updatePost(userId, postId, request), "성공적으로 수정되었습니다.", HttpStatus.OK);
89+ // }
90+ //
91+ // @DeleteMapping("/{postId}")
92+ // @Operation(summary = "게시글 삭제", description = "게시글 ID로 게시글을 삭제합니다.")
93+ // public ApiResponse<Void> deletePost(
94+ // @Parameter(description = "삭제할 게시글 ID", required = true) @PathVariable Long postId,
95+ // @RequestParam Long userId) {
96+ // postService.deletePost(userId, postId);
97+ // return ApiResponse.success(null, "성공적으로 삭제되었습니다.", HttpStatus.OK);
98+ // }
99+
44100}
0 commit comments