66import inu .codin .codin .domain .post .dto .request .PostContentUpdateRequestDTO ;
77import inu .codin .codin .domain .post .dto .request .PostCreateRequestDTO ;
88import inu .codin .codin .domain .post .dto .request .PostStatusUpdateRequestDTO ;
9- import inu .codin .codin .domain .post .dto .response .PostDetailResponseDTO ;
109import inu .codin .codin .domain .post .dto .response .PostPageResponse ;
10+ import inu .codin .codin .domain .post .dto .response .PostPageItemResponseDTO ;
1111import inu .codin .codin .domain .post .entity .PostCategory ;
12- import inu .codin .codin .domain .post .service .PostService ;
12+ import inu .codin .codin .domain .post .service .PostCommandService ;
13+ import inu .codin .codin .domain .post .service .PostQueryService ;
1314import io .swagger .v3 .oas .annotations .Operation ;
1415import io .swagger .v3 .oas .annotations .tags .Tag ;
1516import jakarta .validation .Valid ;
1617import jakarta .validation .constraints .NotNull ;
1718import jakarta .validation .constraints .Size ;
19+ import lombok .RequiredArgsConstructor ;
1820import org .springframework .http .HttpStatus ;
1921import org .springframework .http .MediaType ;
2022import org .springframework .http .ResponseEntity ;
2729@ RestController
2830@ RequestMapping ("/posts" )
2931@ Validated
32+ @ RequiredArgsConstructor
3033@ Tag (name = "POST API" , description = "게시글 API" )
3134public class PostController {
3235
33- private final PostService postService ;
34-
35- public PostController (PostService postService ) {
36- this .postService = postService ;
37- }
36+ private final PostCommandService postCommandService ;
37+ private final PostQueryService postQueryService ;
3838
3939 @ Operation (
4040 summary = "게시물 작성" ,
4141 description = "JSON 형식의 게시물 데이터(postContent)와 이미지 파일(postImages) 업로드"
4242 )
4343 @ PostMapping (consumes = MediaType .MULTIPART_FORM_DATA_VALUE )
44- public ResponseEntity <SingleResponse <? >> createPost (
44+ public ResponseEntity <SingleResponse <Void >> createPost (
4545 @ RequestPart ("postContent" ) @ Valid PostCreateRequestDTO postCreateRequestDTO ,
4646 @ RequestPart (value = "postImages" , required = false ) List <MultipartFile > postImages ) {
4747
4848 // postImages가 null이면 빈 리스트로 처리
4949 if (postImages == null ) postImages = List .of ();
50+ postCommandService .createPost (postCreateRequestDTO , postImages );
5051 return ResponseEntity .status (HttpStatus .CREATED )
51- .body (new SingleResponse <>(201 , "게시물이 작성되었습니다." , postService . createPost ( postCreateRequestDTO , postImages ) ));
52+ .body (new SingleResponse <>(201 , "게시물이 작성되었습니다." , null ));
5253 }
5354
5455 @ Operation (
5556 summary = "게시물 내용 수정 및 이미지 수정&추가"
5657 )
5758 @ PatchMapping (value = "/{postId}/content" , consumes = MediaType .MULTIPART_FORM_DATA_VALUE )
58- public ResponseEntity <SingleResponse <? >> updatePostContent (
59+ public ResponseEntity <SingleResponse <Void >> updatePostContent (
5960 @ PathVariable String postId ,
6061 @ RequestPart ("postContent" ) @ Valid PostContentUpdateRequestDTO requestDTO ,
6162 @ RequestPart (value = "postImages" , required = false ) List <MultipartFile > postImages ) {
6263
63- postService .updatePostContent (postId , requestDTO , postImages );
64+ postCommandService .updatePostContent (postId , requestDTO , postImages );
6465 return ResponseEntity .status (HttpStatus .OK )
6566 .body (new SingleResponse <>(200 , "게시물 내용이 수정되었습니다." , null ));
6667 }
@@ -69,21 +70,21 @@ public ResponseEntity<SingleResponse<?>> updatePostContent(
6970 summary = "상태 수정"
7071 )
7172 @ PatchMapping ("/{postId}/status" )
72- public ResponseEntity <SingleResponse <? >> updatePostStatus (
73+ public ResponseEntity <SingleResponse <Void >> updatePostStatus (
7374 @ PathVariable String postId ,
7475 @ RequestBody PostStatusUpdateRequestDTO requestDTO ) {
75- postService .updatePostStatus (postId , requestDTO );
76+ postCommandService .updatePostStatus (postId , requestDTO );
7677 return ResponseEntity .status (HttpStatus .OK )
7778 .body (new SingleResponse <>(200 , "게시물 상태가 수정되었습니다." , null ));
7879 }
7980
8081
8182 @ Operation (summary = "게시물 익명 설정 수정" )
8283 @ PatchMapping ("/{postId}/anonymous" )
83- public ResponseEntity <SingleResponse <? >> updatePostAnonymous (
84+ public ResponseEntity <SingleResponse <Void >> updatePostAnonymous (
8485 @ PathVariable String postId ,
8586 @ RequestBody @ Valid PostAnonymousUpdateRequestDTO requestDTO ) {
86- postService .updatePostAnonymous (postId , requestDTO );
87+ postCommandService .updatePostAnonymous (postId , requestDTO );
8788 return ResponseEntity .status (HttpStatus .OK )
8889 .body (new SingleResponse <>(200 , "게시물 익명 설정이 수정되었습니다." , null ));
8990 }
@@ -95,36 +96,36 @@ public ResponseEntity<SingleResponse<?>> updatePostAnonymous(
9596 @ GetMapping ("/category" )
9697 public ResponseEntity <SingleResponse <PostPageResponse >> getAllPosts (@ RequestParam PostCategory postCategory ,
9798 @ RequestParam ("page" ) @ NotNull int pageNumber ) {
98- PostPageResponse postpages = postService .getAllPosts (postCategory , pageNumber );
99+ PostPageResponse postpages = postQueryService .getAllPosts (postCategory , pageNumber );
99100 return ResponseEntity .ok ()
100101 .body (new SingleResponse <>(200 , "카테고리별 삭제 되지 않은 모든 게시물 조회 성공" , postpages ));
101102 }
102103
103104
104105 @ Operation (summary = "해당 게시물 상세 조회 (댓글 조회는 Comment에서 따로 조회)" )
105106 @ GetMapping ("/{postId}" )
106- public ResponseEntity <SingleResponse <PostDetailResponseDTO >> getPostWithDetail (@ PathVariable String postId ) {
107- PostDetailResponseDTO post = postService .getPostWithDetail (postId );
107+ public ResponseEntity <SingleResponse <PostPageItemResponseDTO >> getPostWithDetail (@ PathVariable String postId ) {
108+ PostPageItemResponseDTO post = postQueryService .getPostWithDetail (postId );
108109 return ResponseEntity .ok ()
109110 .body (new SingleResponse <>(200 , "게시물 상세 조회 성공" , post ));
110111 }
111112
112113
113114 @ Operation (summary = "게시물 이미지 삭제" )
114115 @ DeleteMapping ("/{postId}/images" )
115- public ResponseEntity <SingleResponse <? >> deletePostImage (
116+ public ResponseEntity <SingleResponse <Void >> deletePostImage (
116117 @ PathVariable String postId ,
117118 @ RequestParam String imageUrl ) {
118119
119- postService .deletePostImage (postId , imageUrl );
120+ postCommandService .deletePostImage (postId , imageUrl );
120121 return ResponseEntity .ok ()
121122 .body (new SingleResponse <>(200 , "게시물 이미지가 삭제되었습니다." , null ));
122123 }
123124
124125 @ Operation (summary = "게시물 삭제 (Soft Delete)" )
125126 @ DeleteMapping ("/{postId}" )
126- public ResponseEntity <SingleResponse <? >> softDeletePost (@ PathVariable String postId ) {
127- postService .softDeletePost (postId );
127+ public ResponseEntity <SingleResponse <Void >> softDeletePost (@ PathVariable String postId ) {
128+ postCommandService .softDeletePost (postId );
128129 return ResponseEntity .ok ()
129130 .body (new SingleResponse <>(200 , "게시물이 삭제되었습니다." , null ));
130131 }
@@ -133,23 +134,23 @@ public ResponseEntity<SingleResponse<?>> softDeletePost(@PathVariable String pos
133134 summary = "검색 엔진"
134135 )
135136 @ GetMapping ("/search" )
136- public ResponseEntity <SingleResponse <? >> searchPosts (@ RequestParam ("keyword" ) @ Size (min = 2 ) String keyword ,
137+ public ResponseEntity <SingleResponse <PostPageResponse >> searchPosts (@ RequestParam ("keyword" ) @ Size (min = 2 ) String keyword ,
137138 @ RequestParam ("pageNumber" ) @ NotNull int pageNumber ){
138139 return ResponseEntity .ok ()
139- .body (new SingleResponse <>(200 , "'" +keyword +"'" +"으로 검색된 게시글 반환 완료" , postService .searchPosts (keyword , pageNumber )));
140+ .body (new SingleResponse <>(200 , "'" +keyword +"'" +"으로 검색된 게시글 반환 완료" , postQueryService .searchPosts (keyword , pageNumber )));
140141 }
141142
142143 @ Operation (summary = "Top 3 베스트 게시글 가져오기" )
143144 @ GetMapping ("/top3" )
144- public ResponseEntity <ListResponse <? >> getTop3BestPosts (){
145+ public ResponseEntity <ListResponse <PostPageItemResponseDTO >> getTop3BestPosts (){
145146 return ResponseEntity .ok ()
146- .body (new ListResponse <>(200 , "Top3 베스트 게시글 반환 완료" , postService .getTop3BestPosts ()));
147+ .body (new ListResponse <>(200 , "Top3 베스트 게시글 반환 완료" , postQueryService .getTop3BestPosts ()));
147148 }
148149
149150 @ Operation (summary = "Top3로 선정된 게시글들 모두 가져오기" )
150151 @ GetMapping ("/best" )
151- public ResponseEntity <SingleResponse <? >> getBestPosts (@ RequestParam ("pageNumber" ) int pageNumber ){
152+ public ResponseEntity <SingleResponse <PostPageResponse >> getBestPosts (@ RequestParam ("pageNumber" ) int pageNumber ){
152153 return ResponseEntity .ok ()
153- .body (new SingleResponse <>(200 , "Top3로 선정된 게시글들 모두 반환 완료" , postService .getBestPosts (pageNumber )));
154+ .body (new SingleResponse <>(200 , "Top3로 선정된 게시글들 모두 반환 완료" , postQueryService .getBestPosts (pageNumber )));
154155 }
155156}
0 commit comments