55import com .back .domain .party .party .entity .PartyMember ;
66import com .back .domain .party .party .service .PartyService ;
77import com .back .global .common .ApiResponse ;
8+ import com .back .global .exception .CustomException ;
9+ import com .back .global .exception .ErrorCode ;
810import io .swagger .v3 .oas .annotations .Operation ;
911import io .swagger .v3 .oas .annotations .tags .Tag ;
1012import jakarta .validation .Valid ;
1113import lombok .RequiredArgsConstructor ;
1214import org .springframework .http .HttpStatus ;
1315import org .springframework .http .ResponseEntity ;
16+ import org .springframework .security .core .Authentication ;
1417import org .springframework .web .bind .annotation .*;
1518
1619import java .util .List ;
@@ -24,12 +27,25 @@ public class ApiV1PartyController {
2427
2528 private final PartyService partyService ;
2629
30+ // Authentication 객체로부터 사용자 ID를 안전하게 가져오는 헬퍼 메서드
31+ private Integer getMemberIdFromAuthentication (Authentication authentication ) {
32+ if (authentication == null || authentication .getName () == null ) {
33+ throw new IllegalArgumentException ("인증 정보가 없습니다." );
34+ }
35+ try {
36+ return Integer .parseInt (authentication .getName ());
37+ } catch (NumberFormatException e ) {
38+ throw new CustomException (ErrorCode .UNAUTHORIZED , "유효하지 않은 인증 정보입니다." );
39+ }
40+ }
41+
2742 @ PostMapping
2843 @ Operation (summary = "파티 생성" , description = "파티를 생성하는 API" )
2944 public ResponseEntity <ApiResponse <PartyDto >> createParty (
3045 @ Valid @ RequestBody PartyRequestDto requestDto ,
31- @ RequestParam ( "memberId" ) Integer memberId
46+ Authentication authentication
3247 ) {
48+ Integer memberId = getMemberIdFromAuthentication (authentication );
3349 Party createdParty = partyService .createParty (requestDto , memberId );
3450 PartyDto partyDto = new PartyDto (createdParty );
3551
@@ -42,8 +58,9 @@ public ResponseEntity<ApiResponse<PartyDto>> createParty(
4258 @ Operation (summary = "공개 파티 가입 신청" , description = "공개 파티에 가입을 신청하는 API. 파티장이 수락해야 가입 완료됩니다." )
4359 public ResponseEntity <ApiResponse <Void >> joinParty (
4460 @ PathVariable Integer partyId ,
45- @ RequestParam ( "memberId" ) Integer memberId
61+ Authentication authentication
4662 ) {
63+ Integer memberId = getMemberIdFromAuthentication (authentication );
4764 partyService .joinParty (partyId , memberId );
4865
4966 return ResponseEntity
@@ -55,8 +72,9 @@ public ResponseEntity<ApiResponse<Void>> joinParty(
5572 @ Operation (summary = "파티 탈퇴" , description = "가입된 파티를 탈퇴하는 API" )
5673 public ResponseEntity <ApiResponse <Void >> leaveParty (
5774 @ PathVariable Integer partyId ,
58- @ RequestParam ( "memberId" ) Integer memberId
75+ Authentication authentication
5976 ) {
77+ Integer memberId = getMemberIdFromAuthentication (authentication );
6078 partyService .leaveParty (partyId , memberId );
6179
6280 return ResponseEntity
@@ -69,8 +87,9 @@ public ResponseEntity<ApiResponse<Void>> leaveParty(
6987 public ResponseEntity <ApiResponse <Void >> updateParty (
7088 @ PathVariable Integer partyId ,
7189 @ Valid @ RequestBody PartyUpdateRequestDto requestDto ,
72- @ RequestParam ( "memberId" ) Integer memberId
90+ Authentication authentication
7391 ) {
92+ Integer memberId = getMemberIdFromAuthentication (authentication );
7493 partyService .updateParty (partyId , requestDto , memberId );
7594
7695 return ResponseEntity
@@ -82,8 +101,9 @@ public ResponseEntity<ApiResponse<Void>> updateParty(
82101 @ Operation (summary = "파티 삭제" , description = "파티를 삭제하는 API" )
83102 public ResponseEntity <ApiResponse <Void >> deleteParty (
84103 @ PathVariable Integer partyId ,
85- @ RequestParam ( "memberId" ) Integer memberId
104+ Authentication authentication
86105 ) {
106+ Integer memberId = getMemberIdFromAuthentication (authentication );
87107 partyService .deleteParty (partyId , memberId );
88108
89109 return ResponseEntity
@@ -119,9 +139,10 @@ public ResponseEntity<ApiResponse<PartyDto>> getPartyDetails(@PathVariable Integ
119139 @ Operation (summary = "파티 초대 (코드)" , description = "파티장이 다른 멤버를 코드를 사용하여 파티에 초대하는 API" )
120140 public ResponseEntity <ApiResponse <Void >> inviteMember (
121141 @ PathVariable Integer partyId ,
122- @ RequestParam ( "leaderId" ) Integer leaderId ,
123- @ RequestBody @ Valid InvitationDto invitationDto
142+ @ RequestBody @ Valid InvitationDto invitationDto ,
143+ Authentication authentication
124144 ) {
145+ Integer leaderId = getMemberIdFromAuthentication (authentication );
125146 partyService .inviteMember (partyId , leaderId , invitationDto .getInvitedMemberCode ());
126147
127148 return ResponseEntity
@@ -133,8 +154,9 @@ public ResponseEntity<ApiResponse<Void>> inviteMember(
133154 @ Operation (summary = "초대/신청 수락" , description = "초대/신청 대기 중인 멤버를 파티원이 되도록 수락하는 API" )
134155 public ResponseEntity <ApiResponse <Void >> acceptInvitation (
135156 @ PathVariable Integer partyId ,
136- @ RequestParam ( "memberId" ) Integer memberId
157+ Authentication authentication
137158 ) {
159+ Integer memberId = getMemberIdFromAuthentication (authentication );
138160 partyService .acceptInvitation (partyId , memberId );
139161 return ResponseEntity
140162 .status (HttpStatus .OK )
@@ -145,8 +167,9 @@ public ResponseEntity<ApiResponse<Void>> acceptInvitation(
145167 @ Operation (summary = "초대/신청 거절" , description = "초대/신청 대기 중인 멤버를 거절하는 API" )
146168 public ResponseEntity <ApiResponse <Void >> rejectInvitation (
147169 @ PathVariable Integer partyId ,
148- @ RequestParam ( "memberId" ) Integer memberId
170+ Authentication authentication
149171 ) {
172+ Integer memberId = getMemberIdFromAuthentication (authentication );
150173 partyService .rejectInvitation (partyId , memberId );
151174 return ResponseEntity
152175 .status (HttpStatus .OK )
@@ -157,9 +180,10 @@ public ResponseEntity<ApiResponse<Void>> rejectInvitation(
157180 @ Operation (summary = "파티원 추방" , description = "파티장이 특정 파티원을 추방하는 API" )
158181 public ResponseEntity <ApiResponse <Void >> kickMember (
159182 @ PathVariable Integer partyId ,
160- @ RequestParam ( "leaderId" ) Integer leaderId ,
183+ Authentication authentication ,
161184 @ PathVariable Integer kickedMemberId
162185 ) {
186+ Integer leaderId = getMemberIdFromAuthentication (authentication );
163187 partyService .kickMember (partyId , leaderId , kickedMemberId );
164188
165189 return ResponseEntity
@@ -171,8 +195,9 @@ public ResponseEntity<ApiResponse<Void>> kickMember(
171195 @ Operation (summary = "파티 가입 신청/초대 목록 조회" , description = "파티장이 가입 신청 또는 초대 대기 중인 멤버 목록을 조회하는 API" )
172196 public ResponseEntity <ApiResponse <List <PartyMemberDto >>> getPendingJoinRequests (
173197 @ PathVariable Integer partyId ,
174- @ RequestParam ( "leaderId" ) Integer leaderId
198+ Authentication authentication
175199 ) {
200+ Integer leaderId = getMemberIdFromAuthentication (authentication );
176201 List <PartyMember > pendingRequests = partyService .getPendingJoinRequests (partyId , leaderId );
177202 List <PartyMemberDto > requestDtos = pendingRequests .stream ()
178203 .map (pm -> new PartyMemberDto (pm .getMember ()))
0 commit comments