11package com .blockcloud .controller ;
22
3- import com .blockcloud .dto .common .CommonResponse ;
43import com .blockcloud .dto .RequestDto .ProjectRequestDto ;
54import com .blockcloud .dto .ResponseDto .ProjectListResponseDto ;
65import com .blockcloud .dto .ResponseDto .ProjectResponseDto ;
6+ import com .blockcloud .dto .common .ResponseDto ;
77import com .blockcloud .dto .oauth .CustomUserDetails ;
88import com .blockcloud .service .ProjectService ;
99import io .swagger .v3 .oas .annotations .Operation ;
1414import io .swagger .v3 .oas .annotations .responses .ApiResponses ;
1515import io .swagger .v3 .oas .annotations .tags .Tag ;
1616import jakarta .validation .Valid ;
17- import org .springframework .http .HttpStatus ;
18- import org .springframework .http .ResponseEntity ;
17+ import lombok .RequiredArgsConstructor ;
1918import org .springframework .security .core .Authentication ;
2019import org .springframework .web .bind .annotation .*;
2120
2524@ Tag (name = "Project API" , description = "프로젝트 생성, 조회, 수정, 삭제 관련 API" )
2625@ RestController
2726@ RequestMapping ("/api/projects" )
27+ @ RequiredArgsConstructor
2828public class ProjectController {
2929
3030 private final ProjectService projectService ;
3131
32- public ProjectController (ProjectService projectService ) {
33- this .projectService = projectService ;
34- }
35-
3632 /**
3733 * 새로운 프로젝트를 생성합니다.
3834 *
@@ -45,25 +41,17 @@ public ProjectController(ProjectService projectService) {
4541 description = "새로운 프로젝트를 생성합니다. 요청 바디에 `name`, `description`을 포함해야 하며, JWT 토큰이 필요합니다."
4642 )
4743 @ ApiResponses (value = {
48- @ ApiResponse (responseCode = "200 " , description = "프로젝트 생성 성공" ,
49- content = @ Content (schema = @ Schema (implementation = ProjectResponseDto .class ))),
50- @ ApiResponse (responseCode = "400" , description = "잘못된 요청 데이터" ),
51- @ ApiResponse (responseCode = "401" , description = "인증 실패 (JWT 필요 )" )
44+ @ ApiResponse (responseCode = "201 " , description = "프로젝트 생성 성공" ,
45+ content = @ Content (schema = @ Schema (implementation = ResponseDto .class ))),
46+ @ ApiResponse (responseCode = "400" , description = "INVALID_ARGUMENT ( 요청 데이터 유효성 검증 실패) " ),
47+ @ ApiResponse (responseCode = "401" , description = "UNAUTHORIZED (인증 실패 )" )
5248 })
5349 @ PostMapping
54- public ResponseEntity <ProjectResponseDto > create (
55- @ io .swagger .v3 .oas .annotations .parameters .RequestBody (
56- description = "생성할 프로젝트 정보 (name: 프로젝트 이름, description: 설명)" ,
57- required = true
58- )
59- @ RequestBody @ Valid ProjectRequestDto dto ,
50+ public ResponseDto <ProjectResponseDto > create (
51+ @ Valid @ RequestBody ProjectRequestDto dto ,
6052 Authentication authentication ) {
61-
6253 CustomUserDetails userDetails = (CustomUserDetails ) authentication .getPrincipal ();
63- String email = userDetails .getUsername ();
64-
65- ProjectResponseDto response = projectService .create (dto , email );
66- return ResponseEntity .status (HttpStatus .CREATED ).body (response );
54+ return ResponseDto .created (projectService .create (dto , userDetails .getUsername ()));
6755 }
6856
6957 /**
@@ -79,17 +67,15 @@ public ResponseEntity<ProjectResponseDto> create(
7967 )
8068 @ ApiResponses (value = {
8169 @ ApiResponse (responseCode = "200" , description = "조회 성공" ,
82- content = @ Content (mediaType = "application/json" , schema = @ Schema (implementation = ProjectListResponseDto .class ))),
83- @ ApiResponse (responseCode = "401" , description = "인증 실패 (JWT 필요)" )
70+ content = @ Content (schema = @ Schema (implementation = ResponseDto .class )))
8471 })
8572 @ GetMapping
86- public ResponseEntity <ProjectListResponseDto > getProjects (
73+ public ResponseDto <ProjectListResponseDto > getProjects (
8774 @ Parameter (description = "마지막으로 조회한 프로젝트 ID (첫 호출 시 생략 가능)" )
8875 @ RequestParam (required = false ) Long lastId ,
8976 @ Parameter (description = "가져올 데이터 개수 (기본값 8)" )
9077 @ RequestParam (defaultValue = "8" ) int size ) {
91-
92- return ResponseEntity .ok (projectService .findNext (lastId , size ));
78+ return ResponseDto .ok (projectService .findNext (lastId , size ));
9379 }
9480
9581 /**
@@ -105,26 +91,19 @@ public ResponseEntity<ProjectListResponseDto> getProjects(
10591 )
10692 @ ApiResponses (value = {
10793 @ ApiResponse (responseCode = "200" , description = "수정 성공" ,
108- content = @ Content (schema = @ Schema (implementation = ProjectResponseDto .class ))),
109- @ ApiResponse (responseCode = "401" , description = "인증 실패 (JWT 필요)" ),
110- @ ApiResponse (responseCode = "403" , description = "접근 권한 없음" ),
111- @ ApiResponse (responseCode = "404" , description = "프로젝트를 찾을 수 없음" )
94+ content = @ Content (schema = @ Schema (implementation = ResponseDto .class ))),
95+ @ ApiResponse (responseCode = "400" , description = "INVALID_ARGUMENT (요청 데이터 유효성 검증 실패)" ),
96+ @ ApiResponse (responseCode = "401" , description = "UNAUTHORIZED (인증 실패)" ),
97+ @ ApiResponse (responseCode = "403" , description = "FORBIDDEN (접근 권한 없음)" ),
98+ @ ApiResponse (responseCode = "404" , description = "NOT_FOUND (프로젝트를 찾을 수 없음)" )
11299 })
113100 @ PutMapping ("/{projectId}" )
114- public ResponseEntity <ProjectResponseDto > update (
115- @ Parameter (description = "수정할 프로젝트 ID" , required = true )
116- @ PathVariable Long projectId ,
117- @ io .swagger .v3 .oas .annotations .parameters .RequestBody (
118- description = "수정할 프로젝트 정보 (name, description 포함)" ,
119- required = true
120- )
121- @ RequestBody @ Valid ProjectRequestDto dto ,
101+ public ResponseDto <ProjectResponseDto > update (
102+ @ Parameter (description = "수정할 프로젝트 ID" , required = true ) @ PathVariable Long projectId ,
103+ @ Valid @ RequestBody ProjectRequestDto dto ,
122104 Authentication authentication ) {
123-
124105 CustomUserDetails userDetails = (CustomUserDetails ) authentication .getPrincipal ();
125- String email = userDetails .getUsername ();
126-
127- return ResponseEntity .ok (projectService .update (projectId , dto , email ));
106+ return ResponseDto .ok (projectService .update (projectId , dto , userDetails .getUsername ()));
128107 }
129108
130109 /**
@@ -138,22 +117,18 @@ public ResponseEntity<ProjectResponseDto> update(
138117 description = "프로젝트를 삭제합니다. JWT 인증 필요."
139118 )
140119 @ ApiResponses (value = {
141- @ ApiResponse (responseCode = "200" , description = "삭제 성공" ,
142- content = @ Content (schema = @ Schema (implementation = CommonResponse .class ))),
143- @ ApiResponse (responseCode = "401" , description = "인증 실패 (JWT 필요)" ),
144- @ ApiResponse (responseCode = "403" , description = "접근 권한 없음" ),
145- @ ApiResponse (responseCode = "404" , description = "프로젝트를 찾을 수 없음" )
120+ @ ApiResponse (responseCode = "204" , description = "삭제 성공" ),
121+ @ ApiResponse (responseCode = "401" , description = "UNAUTHORIZED (인증 실패)" ),
122+ @ ApiResponse (responseCode = "403" , description = "FORBIDDEN (접근 권한 없음)" ),
123+ @ ApiResponse (responseCode = "404" , description = "NOT_FOUND (프로젝트를 찾을 수 없음)" )
146124 })
147125 @ DeleteMapping ("/{projectId}" )
148- public ResponseEntity < CommonResponse > delete (
126+ public ResponseDto < Object > delete (
149127 @ Parameter (description = "삭제할 프로젝트 ID" , required = true )
150128 @ PathVariable Long projectId ,
151129 Authentication authentication ) {
152-
153130 CustomUserDetails userDetails = (CustomUserDetails ) authentication .getPrincipal ();
154- String email = userDetails .getUsername ();
155-
156- projectService .delete (projectId , email );
157- return ResponseEntity .ok (new CommonResponse (true , "프로젝트를 성공적으로 삭제했습니다." ));
131+ projectService .delete (projectId , userDetails .getUsername ());
132+ return ResponseDto .noContent ();
158133 }
159134}
0 commit comments