Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,18 @@ public BaseResponse<ProfileImageResponse> uploadOrReplaceProfileImage(
String key = profileImageService.updateProfileImage(pd.getMemberId(), image);
return BaseResponse.onSuccess(SuccessStatus._OK, new ProfileImageResponse(key));
}

@Operation(
summary = "프로필 이미지 조회 API",
description = "# [v1.0 (2025-09-18)](https://clumsy-seeder-416.notion.site/2711197c19ed8039bbe2c48380c9f4c8?source=copy_link)\n" +
"- 로그인한 사용자의 프로필 이미지 presigned URL을 반환합니다.\n" +
"- URL은 일정 시간 동안만 유효합니다."
)
@GetMapping("/profile/image")
public BaseResponse<ProfileImageResponse> getProfileImage(
@AuthenticationPrincipal PrincipalDetails pd
) {
String url = profileImageService.getProfileImageUrl(pd.getMemberId());
return BaseResponse.onSuccess(SuccessStatus._OK, new ProfileImageResponse(url));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@

public interface ProfileImageService {
String updateProfileImage(Long memberId, MultipartFile image);
String getProfileImageUrl(Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,27 @@ public String updateProfileImage(Long memberId, MultipartFile image) {
// 5) 호출자에 key 반환 (FE는 필요 시 presigned URL 생성해 사용)
return uploadedKey;
}

@Override
@Transactional(readOnly = true)
public String getProfileImageUrl(Long memberId) {
Member member = memberRepository.findById(memberId)
.orElseThrow(() -> new CustomAuthException(ErrorStatus.NO_SUCH_MEMBER));

String keyOrUrl = member.getProfileUrl();
if (keyOrUrl == null || keyOrUrl.isBlank()) {
throw new CustomAuthException(ErrorStatus.PROFILE_IMAGE_NOT_FOUND);
}

if (keyOrUrl.startsWith("http://") || keyOrUrl.startsWith("https://")) {
return keyOrUrl;
}

String presigned = amazonS3Manager.generatePresignedUrl(keyOrUrl);
if (presigned == null) {
throw new CustomAuthException(ErrorStatus.PROFILE_IMAGE_NOT_FOUND);
}
return presigned;
}
}

4 changes: 2 additions & 2 deletions src/main/java/com/assu/server/infra/s3/AmazonS3Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public String uploadFile(String keyName, byte[] fileBytes, String contentType) {
}


// FE로 url을 보내기 위해 사용하는 메서드
// 그대로 사용
public String generatePresignedUrl(String keyName) {
if (keyName == null || keyName.isBlank()) return null;

Expand All @@ -81,7 +81,7 @@ public String generatePresignedUrl(String keyName) {
.build();

GetObjectPresignRequest presignRequest = GetObjectPresignRequest.builder()
.signatureDuration(Duration.ofMinutes(10))
.signatureDuration(Duration.ofMinutes(10)) // 유효기간 10분
.getObjectRequest(getObjectRequest)
.build();

Expand Down