Skip to content

Commit 8b13ea4

Browse files
Merge pull request #93 from marshmallowing/fix/profile
#92 Fix: 프로필 이미지 가져오는 방식 수정
2 parents 648f8cb + 9b3d5cb commit 8b13ea4

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

src/main/java/com/memesphere/domain/image/controller/ImageController.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
import com.memesphere.domain.image.service.ImageService;
66
import com.memesphere.domain.image.service.ProfileService;
77
import com.memesphere.global.apipayload.ApiResponse;
8+
import com.memesphere.global.jwt.CustomUserDetails;
89
import io.swagger.v3.oas.annotations.Operation;
910
import lombok.RequiredArgsConstructor;
1011
import org.springframework.http.MediaType;
12+
import org.springframework.security.core.annotation.AuthenticationPrincipal;
1113
import org.springframework.web.bind.annotation.*;
1214

1315
@RequestMapping("/image")
@@ -33,14 +35,14 @@ public ApiResponse<PresignedUrlResponse> uploadFile(@RequestBody ImageExtensionR
3335
return ApiResponse.onSuccess(url);
3436
}
3537

36-
//프로필 이미지 조회 Api
37-
@GetMapping("/profile/{user_id}")
38+
// 프로필 이미지 조회 Api
39+
@GetMapping("/profile")
3840
@Operation(summary = "프로필 이미지 조회 API",
39-
description = "회원가입한 유저의 프로필 이미지를 반환합니다.")
40-
public ApiResponse<String> getProfile(@PathVariable("user_id") Long user_id) {
41-
String profileImage = profileService.getProfileImage(user_id);
41+
description = "현재 로그인한 유저의 프로필 이미지를 반환합니다.")
42+
public ApiResponse<String> getProfile(@AuthenticationPrincipal CustomUserDetails customUserDetails) {
43+
// 현재 로그인한 유저 정보에서 프로필 이미지 가져오기
44+
String profileImage = profileService.getProfileImage(customUserDetails);
4245

43-
// null이거나 ""이면 result를 null로 반환
4446
return ApiResponse.onSuccess((profileImage == null || profileImage.isEmpty()) ? "null" : profileImage);
4547
}
4648

src/main/java/com/memesphere/domain/image/service/ProfileService.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,23 @@
44
import com.memesphere.domain.user.repository.UserRepository;
55
import com.memesphere.global.apipayload.code.status.ErrorStatus;
66
import com.memesphere.global.apipayload.exception.GeneralException;
7+
import com.memesphere.global.jwt.CustomUserDetails;
78
import lombok.RequiredArgsConstructor;
9+
import org.springframework.security.core.annotation.AuthenticationPrincipal;
810
import org.springframework.stereotype.Service;
911

1012
@Service
1113
@RequiredArgsConstructor
1214
public class ProfileService {
13-
private final UserRepository userRepository;
1415

1516
// 프로필 이미지 반환
16-
public String getProfileImage(Long userId) {
17-
User user = userRepository.findById(userId)
18-
.orElseThrow(() -> new GeneralException(ErrorStatus.USER_NOT_FOUND));
17+
public String getProfileImage(@AuthenticationPrincipal CustomUserDetails customUserDetails) {
18+
if (customUserDetails == null || customUserDetails.getUser() == null) {
19+
throw new GeneralException(ErrorStatus.USER_NOT_FOUND);
20+
}
21+
22+
User user = customUserDetails.getUser();
1923
return user.getProfileImage();
2024
}
25+
2126
}

0 commit comments

Comments
 (0)