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 @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,23 @@ public class UserController implements UserControllerDocs {
private final FollowService followService;

/**
* 프로필 조회
* 프로필 조회(me)
*/
@GetMapping("/me")
public ResponseEntity<ApiResponse<UserInfoResponse>> 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<ApiResponse<UserInfoResponse>> profile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
@Tag(name = "유저 API", description = "유저와 관련된 API 리스트 \uD83D\uDC08")
public interface UserControllerDocs {

@Operation(summary = "본인 프로필 조회 API", description = "토큰을 통해서 본인 프로필 정보를 조회합니다. (별도 파라메터 없습니다)")
ResponseEntity<ApiResponse<UserInfoResponse>> profile(
@AuthenticationPrincipal CustomUserDetails userDetails
);

@Operation(summary = "유저 프로필 조회 API", description =
"PathVariable로 들어온 userId에 해당하는 유저 프로필에 대한 응답 \n"
+ "로그인 여부/본인 여부에 따라 팔로우 여부를 null 혹은 true/false로 응답합니다.")
Expand Down