diff --git a/src/main/java/team/wego/wegobackend/common/security/JwtAuthenticationFilter.java b/src/main/java/team/wego/wegobackend/common/security/JwtAuthenticationFilter.java index 0dbebb4..1eb98cc 100644 --- a/src/main/java/team/wego/wegobackend/common/security/JwtAuthenticationFilter.java +++ b/src/main/java/team/wego/wegobackend/common/security/JwtAuthenticationFilter.java @@ -130,6 +130,10 @@ private boolean isPublicEndpoint(HttpServletRequest request) { } //TODO : PUBLIC_PATTERNS 관리 포인트 개선 필요 (메서드까지 관리 확장) + if(pathMatcher.match("/api/v1/users/me", path)) { + return false; + } + if ("GET".equals(method) && pathMatcher.match("/api/v1/users/**", path)) { return true; } diff --git a/src/main/java/team/wego/wegobackend/common/security/SecurityConfig.java b/src/main/java/team/wego/wegobackend/common/security/SecurityConfig.java index b589002..610fa35 100644 --- a/src/main/java/team/wego/wegobackend/common/security/SecurityConfig.java +++ b/src/main/java/team/wego/wegobackend/common/security/SecurityConfig.java @@ -35,6 +35,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http .cors(cors -> cors.configurationSource(corsConfigurationSource())) .authorizeHttpRequests((auth) -> auth + .requestMatchers("/api/v1/users/me").authenticated() .requestMatchers(HttpMethod.GET, "/api/v1/users/**").permitAll() .requestMatchers(HttpMethod.GET, "/api/v*/groups/**").permitAll() .requestMatchers(HttpMethod.GET, "/api/v*/groups").permitAll() diff --git a/src/main/java/team/wego/wegobackend/user/application/UserService.java b/src/main/java/team/wego/wegobackend/user/application/UserService.java index d1ff0fd..2855882 100644 --- a/src/main/java/team/wego/wegobackend/user/application/UserService.java +++ b/src/main/java/team/wego/wegobackend/user/application/UserService.java @@ -28,6 +28,15 @@ public class UserService { private final FollowRepository followRepository; private final ImageUploadService imageUploadService; + @Transactional(readOnly = true) + public UserInfoResponse getProfile(Long userId) { + + User user = userRepository.findById(userId) + .orElseThrow(UserNotFoundException::new); + + return UserInfoResponse.from(user); + } + @Transactional(readOnly = true) public UserInfoResponse getProfile(Long loginUserId, Long targetUserId) { @@ -39,9 +48,6 @@ public UserInfoResponse getProfile(Long loginUserId, Long targetUserId) { return UserInfoResponse.from(targetUser); } - User loginUser = userRepository.findById(loginUserId) - .orElseThrow(UserNotFoundException::new); - boolean isFollow = followRepository.existsByFollowerIdAndFolloweeId(loginUserId, targetUserId); diff --git a/src/main/java/team/wego/wegobackend/user/presentation/UserController.java b/src/main/java/team/wego/wegobackend/user/presentation/UserController.java index 7ccd62b..1353344 100644 --- a/src/main/java/team/wego/wegobackend/user/presentation/UserController.java +++ b/src/main/java/team/wego/wegobackend/user/presentation/UserController.java @@ -41,7 +41,23 @@ public class UserController implements UserControllerDocs { private final FollowService followService; /** - * 프로필 조회 + * 프로필 조회(me) + */ + @GetMapping("/me") + public ResponseEntity> profile( + @AuthenticationPrincipal CustomUserDetails userDetails + ) { + + UserInfoResponse response = userService.getProfile(userDetails.getId()); + + return ResponseEntity + .status(HttpStatus.OK) + .body(ApiResponse.success(200, + response)); + } + + /** + * 프로필 조회(other) */ @GetMapping("/{userId}") public ResponseEntity> profile( diff --git a/src/main/java/team/wego/wegobackend/user/presentation/UserControllerDocs.java b/src/main/java/team/wego/wegobackend/user/presentation/UserControllerDocs.java index 461b7dc..f0b52f4 100644 --- a/src/main/java/team/wego/wegobackend/user/presentation/UserControllerDocs.java +++ b/src/main/java/team/wego/wegobackend/user/presentation/UserControllerDocs.java @@ -23,6 +23,11 @@ @Tag(name = "유저 API", description = "유저와 관련된 API 리스트 \uD83D\uDC08") public interface UserControllerDocs { + @Operation(summary = "본인 프로필 조회 API", description = "토큰을 통해서 본인 프로필 정보를 조회합니다. (별도 파라메터 없습니다)") + ResponseEntity> profile( + @AuthenticationPrincipal CustomUserDetails userDetails + ); + @Operation(summary = "유저 프로필 조회 API", description = "PathVariable로 들어온 userId에 해당하는 유저 프로필에 대한 응답 \n" + "로그인 여부/본인 여부에 따라 팔로우 여부를 null 혹은 true/false로 응답합니다.")