1919import java .time .LocalDateTime ;
2020import java .util .UUID ;
2121import lombok .RequiredArgsConstructor ;
22- import org .springframework .security .access .prepost . PreAuthorize ;
22+ import org .springframework .security .access .annotation . Secured ;
2323import org .springframework .security .core .annotation .AuthenticationPrincipal ;
24- import org .springframework .security .core .context .SecurityContextHolder ;
2524import org .springframework .web .bind .annotation .DeleteMapping ;
2625import org .springframework .web .bind .annotation .PatchMapping ;
2726import org .springframework .web .bind .annotation .PathVariable ;
3332import org .springframework .web .bind .annotation .RestController ;
3433import org .springframework .web .multipart .MultipartFile ;
3534
36- @ Tag (name = "RecruitBoard " , description = "봉사 활동 모집글 생성 수정 삭제 API" )
35+ @ Tag (name = "Recruit Board Command API " , description = "봉사 활동 모집글 생성 수정 삭제 API" )
3736@ RequiredArgsConstructor
3837@ RequestMapping ("/api" )
3938@ RestController
@@ -44,23 +43,25 @@ public class RecruitBoardCommandApiController {
4443 private final DeleteRecruitBoardUseCase deleteRecruitBoardUseCase ;
4544 private final ImageUploadUseCase imageUploadUseCase ;
4645
47- @ PreAuthorize ( "hasRole('CENTER') " )
46+ @ Secured ( "ROLE_CENTER " )
4847 @ Operation (summary = "봉사 활동 모집글 등록" , description = "봉사 활동 모집글을 등록합니다." )
4948 @ PostMapping (value = "/recruit-board" , consumes = MULTIPART_FORM_DATA_VALUE )
5049 public ApiResponse <Long > createRecruitBoard (
50+ @ AuthenticationPrincipal String userId ,
5151 @ Valid @ RequestPart ("data" ) RecruitBoardCreateRequestDto requestDto ,
52- @ RequestPart ("img_file" ) MultipartFile image
52+ @ RequestPart (value = "img_file" , required = false ) MultipartFile image
5353 ) {
5454
5555 String imgUrl = imageUploadUseCase .uploadImage (new ImageUploadRequestDto (image ));
5656 return ApiResponse .ok (
5757 201 ,
58- createRecruitBoardUseCase .createRecruitBoard (requestDto , getCenterId (), imgUrl ),
58+ createRecruitBoardUseCase .createRecruitBoard (requestDto , getCenterId (userId ),
59+ imgUrl ),
5960 "봉사 활동 모집글 등록 성공"
6061 );
6162 }
6263
63- @ PreAuthorize ( "hasRole('CENTER') " )
64+ @ Secured ( "ROLE_CENTER " )
6465 @ Operation (summary = "봉사 활동 모집글 수정" , description = "봉사 활동 모집글을 수정합니다." )
6566 @ PutMapping (value = "/recruit-board/{id}" , consumes = MULTIPART_FORM_DATA_VALUE )
6667 public ApiResponse <String > updateRecruitBoard (
@@ -70,12 +71,12 @@ public ApiResponse<String> updateRecruitBoard(
7071 @ RequestPart ("img_file" ) MultipartFile image
7172 ) {
7273 String imgUrl = imageUploadUseCase .uploadImage (new ImageUploadRequestDto (image ));
73- updateRecruitBoardUseCase .updateRecruitBoard (requestDto , id , getCenterId (), imgUrl );
74+ updateRecruitBoardUseCase .updateRecruitBoard (requestDto , id , getCenterId (userId ), imgUrl );
7475
7576 return ApiResponse .ok ("봉사 활동 모집글 수정 성공" );
7677 }
7778
78- @ PreAuthorize ( "hasRole('CENTER') " )
79+ @ Secured ( "ROLE_CENTER " )
7980 @ Operation (summary = "봉사 활동 모집글 위치 수정" , description = "봉사 활동 모집글의 위치를 수정합니다." )
8081 @ PutMapping (value = "/recruit-board/{id}/location" )
8182 public ApiResponse <String > updateRecruitBoardLocation (
@@ -84,11 +85,11 @@ public ApiResponse<String> updateRecruitBoardLocation(
8485 @ Valid @ RequestBody RecruitBoardLocationUpdateRequestDto requestDto
8586 ) {
8687
87- updateRecruitBoardUseCase .updateRecruitBoardLocation (requestDto , id , getCenterId ());
88+ updateRecruitBoardUseCase .updateRecruitBoardLocation (requestDto , id , getCenterId (userId ));
8889 return ApiResponse .ok ("봉사 활동 모집글 위치 수정 성공" );
8990 }
9091
91- @ PreAuthorize ( "hasRole('CENTER') " )
92+ @ Secured ( "ROLE_CENTER " )
9293 @ Operation (summary = "봉사 활동 모집글 상태 수정" , description = "봉사 활동 모집글의 상태를 수정합니다." )
9394 @ PatchMapping (value = "/recruit-board/{id}" )
9495 public ApiResponse <String > updateRecruitBoardStatus (
@@ -97,25 +98,26 @@ public ApiResponse<String> updateRecruitBoardStatus(
9798 @ RequestBody RecruitBoardStatusUpdateRequestDto requestDto
9899 ) {
99100 LocalDateTime now = LocalDateTime .now ();
100- updateRecruitBoardUseCase .updateRecruitBoardStatus (requestDto .status (), id , getCenterId (),
101+ updateRecruitBoardUseCase .updateRecruitBoardStatus (requestDto .status (), id ,
102+ getCenterId (userId ),
101103 now );
102104
103105 return ApiResponse .ok ("봉사 활동 모집글 상태 수정 성공" );
104106 }
105107
106- @ PreAuthorize ( "hasRole('CENTER') " )
108+ @ Secured ( "ROLE_CENTER " )
107109 @ Operation (summary = "봉사 활동 모집글 삭제" , description = "봉사 활동 모집글을 삭제합니다." )
108110 @ DeleteMapping (value = "/recruit-board/{id}" )
109111 public ApiResponse <String > deleteRecruitBoard (
110112 @ AuthenticationPrincipal String userId ,
111113 @ PathVariable Long id
112114 ) {
113- deleteRecruitBoardUseCase .deleteRecruitBoard (getCenterId (), id );
115+ deleteRecruitBoardUseCase .deleteRecruitBoard (getCenterId (userId ), id );
114116 return ApiResponse .ok ("봉사 활동 모집글 삭제 성공" );
115117 }
116118
117- private static UUID getCenterId () {
118- return UUID .fromString (SecurityContextHolder . getContext (). getAuthentication (). getName () );
119+ private static UUID getCenterId (String userId ) {
120+ return UUID .fromString (userId );
119121 }
120122
121123}
0 commit comments