Skip to content

Commit 20e3f84

Browse files
authored
✨feat: 프로필 조회 API 분리 (me, other) (#121)
1 parent eb903fe commit 20e3f84

File tree

5 files changed

+36
-4
lines changed

5 files changed

+36
-4
lines changed

src/main/java/team/wego/wegobackend/common/security/JwtAuthenticationFilter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ private boolean isPublicEndpoint(HttpServletRequest request) {
130130
}
131131

132132
//TODO : PUBLIC_PATTERNS 관리 포인트 개선 필요 (메서드까지 관리 확장)
133+
if(pathMatcher.match("/api/v1/users/me", path)) {
134+
return false;
135+
}
136+
133137
if ("GET".equals(method) && pathMatcher.match("/api/v1/users/**", path)) {
134138
return true;
135139
}

src/main/java/team/wego/wegobackend/common/security/SecurityConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
3535
http
3636
.cors(cors -> cors.configurationSource(corsConfigurationSource()))
3737
.authorizeHttpRequests((auth) -> auth
38+
.requestMatchers("/api/v1/users/me").authenticated()
3839
.requestMatchers(HttpMethod.GET, "/api/v1/users/**").permitAll()
3940
.requestMatchers(HttpMethod.GET, "/api/v*/groups/**").permitAll()
4041
.requestMatchers(HttpMethod.GET, "/api/v*/groups").permitAll()

src/main/java/team/wego/wegobackend/user/application/UserService.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ public class UserService {
2828
private final FollowRepository followRepository;
2929
private final ImageUploadService imageUploadService;
3030

31+
@Transactional(readOnly = true)
32+
public UserInfoResponse getProfile(Long userId) {
33+
34+
User user = userRepository.findById(userId)
35+
.orElseThrow(UserNotFoundException::new);
36+
37+
return UserInfoResponse.from(user);
38+
}
39+
3140
@Transactional(readOnly = true)
3241
public UserInfoResponse getProfile(Long loginUserId, Long targetUserId) {
3342

@@ -39,9 +48,6 @@ public UserInfoResponse getProfile(Long loginUserId, Long targetUserId) {
3948
return UserInfoResponse.from(targetUser);
4049
}
4150

42-
User loginUser = userRepository.findById(loginUserId)
43-
.orElseThrow(UserNotFoundException::new);
44-
4551
boolean isFollow = followRepository.existsByFollowerIdAndFolloweeId(loginUserId,
4652
targetUserId);
4753

src/main/java/team/wego/wegobackend/user/presentation/UserController.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,23 @@ public class UserController implements UserControllerDocs {
4141
private final FollowService followService;
4242

4343
/**
44-
* 프로필 조회
44+
* 프로필 조회(me)
45+
*/
46+
@GetMapping("/me")
47+
public ResponseEntity<ApiResponse<UserInfoResponse>> profile(
48+
@AuthenticationPrincipal CustomUserDetails userDetails
49+
) {
50+
51+
UserInfoResponse response = userService.getProfile(userDetails.getId());
52+
53+
return ResponseEntity
54+
.status(HttpStatus.OK)
55+
.body(ApiResponse.success(200,
56+
response));
57+
}
58+
59+
/**
60+
* 프로필 조회(other)
4561
*/
4662
@GetMapping("/{userId}")
4763
public ResponseEntity<ApiResponse<UserInfoResponse>> profile(

src/main/java/team/wego/wegobackend/user/presentation/UserControllerDocs.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
@Tag(name = "유저 API", description = "유저와 관련된 API 리스트 \uD83D\uDC08")
2424
public interface UserControllerDocs {
2525

26+
@Operation(summary = "본인 프로필 조회 API", description = "토큰을 통해서 본인 프로필 정보를 조회합니다. (별도 파라메터 없습니다)")
27+
ResponseEntity<ApiResponse<UserInfoResponse>> profile(
28+
@AuthenticationPrincipal CustomUserDetails userDetails
29+
);
30+
2631
@Operation(summary = "유저 프로필 조회 API", description =
2732
"PathVariable로 들어온 userId에 해당하는 유저 프로필에 대한 응답 \n"
2833
+ "로그인 여부/본인 여부에 따라 팔로우 여부를 null 혹은 true/false로 응답합니다.")

0 commit comments

Comments
 (0)