11package com .example .FixLog .controller ;
22
3+ import com .example .FixLog .dto .PresignResponseDto ;
34import com .example .FixLog .dto .Response ;
45import com .example .FixLog .dto .member .edit .EditNicknameRequestDto ;
56import com .example .FixLog .dto .member .edit .EditPasswordRequestDto ;
6- import com .example .FixLog .dto .member .edit .EditProfileImageRequestDto ;
77import com .example .FixLog .dto .member .edit .EditBioRequestDto ;
8+ import com .example .FixLog .exception .CustomException ;
9+ import com .example .FixLog .exception .ErrorCode ;
10+ import com .example .FixLog .service .S3Service ;
811import com .example .FixLog .service .MemberService ;
912import com .example .FixLog .domain .member .Member ;
1013import lombok .RequiredArgsConstructor ;
1114import org .springframework .http .ResponseEntity ;
1215import jakarta .validation .Valid ;
13- import org .springframework .web . bind .annotation .PatchMapping ;
14- import org .springframework .web .bind .annotation .RequestBody ;
15- import org . springframework . web . bind . annotation . RequestMapping ;
16- import org . springframework . web . bind . annotation . RestController ;
16+ import org .springframework .security . core .annotation .AuthenticationPrincipal ;
17+ import org .springframework .web .bind .annotation .* ;
18+
19+ import java . util . Map ;
1720
1821@ RestController
1922@ RequiredArgsConstructor
2023@ RequestMapping ("/mypage" )
2124public class MypageMemberController {
2225
2326 private final MemberService memberService ;
27+ private final S3Service s3Service ;
2428
2529 @ PatchMapping ("/members/nickname" )
2630 public ResponseEntity <Response <String >> editNickname (
@@ -40,13 +44,32 @@ public ResponseEntity<Response<String>> editPassword(
4044 return ResponseEntity .ok (Response .success ("비밀번호 변경 성공" , "SUCCESS" ));
4145 }
4246
47+ @ GetMapping ("/members/profile-image/presign" )
48+ public ResponseEntity <Response <PresignResponseDto >> presignProfileImage (
49+ @ AuthenticationPrincipal Member member ,
50+ @ RequestParam String filename
51+ ) {
52+ if (member == null ) throw new CustomException (ErrorCode .UNAUTHORIZED );
53+
54+ String key = s3Service .generateKey ("profile" , filename );
55+ String uploadUrl = s3Service .generatePresignedUrl ("profile" , filename , 15 );
56+ String fileUrl = s3Service .getObjectUrl (key );
57+
58+ PresignResponseDto dto = new PresignResponseDto (uploadUrl , fileUrl );
59+ return ResponseEntity .ok (Response .success ("Presigned URL 발급 성공" , dto ));
60+ }
61+
4362 @ PatchMapping ("/members/profile-image" )
44- public ResponseEntity <Response <String >> editProfileImage (
45- @ RequestBody @ Valid EditProfileImageRequestDto requestDto
63+ public ResponseEntity <Response <String >> updateProfileImageUrl (
64+ @ AuthenticationPrincipal Member member ,
65+ @ RequestBody Map <String , String > body
4666 ) {
47- Member member = memberService .getCurrentMemberInfo ();
48- memberService .editProfileImage (member , requestDto .getProfileImageUrl ());
49- return ResponseEntity .ok (Response .success ("프로필 이미지 수정 성공" , "SUCCESS" ));
67+ String imageUrl = body .get ("imageUrl" );
68+ if (imageUrl == null || imageUrl .isBlank ()) {
69+ throw new CustomException (ErrorCode .INVALID_REQUEST );
70+ }
71+ memberService .editProfileImage (member , imageUrl );
72+ return ResponseEntity .ok (Response .success ("프로필 이미지 저장 성공" , "SUCCESS" ));
5073 }
5174
5275 @ PatchMapping ("/members/bio" )
0 commit comments