54 lines
2.3 KiB
Java
54 lines
2.3 KiB
Java
package com.kamco.cd.kamcoback.user;
|
|
|
|
import com.kamco.cd.kamcoback.config.api.ApiResponseDto;
|
|
import com.kamco.cd.kamcoback.members.dto.MembersDto;
|
|
import com.kamco.cd.kamcoback.user.service.UserInfoService;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.media.Content;
|
|
import io.swagger.v3.oas.annotations.media.Schema;
|
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
|
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.security.core.Authentication;
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
@Tag(name = "사용자 정보", description = "사용자 정보 조회 API")
|
|
@RestController
|
|
@RequiredArgsConstructor
|
|
@RequestMapping("/api/user")
|
|
public class UserApiController {
|
|
|
|
private final UserInfoService userInfoService;
|
|
|
|
@Operation(
|
|
summary = "현재 로그인 사용자 정보 조회",
|
|
description = "JWT 토큰에서 사용자 ID를 추출하여 현재 로그인한 사용자의 정보를 조회합니다.")
|
|
@ApiResponses(
|
|
value = {
|
|
@ApiResponse(
|
|
responseCode = "200",
|
|
description = "조회 성공",
|
|
content =
|
|
@Content(
|
|
mediaType = "application/json",
|
|
schema = @Schema(implementation = MembersDto.EntityData.class))),
|
|
@ApiResponse(
|
|
responseCode = "401",
|
|
description = "인증 실패 (토큰 없음 또는 유효하지 않음)",
|
|
content = @Content),
|
|
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
|
})
|
|
@GetMapping("/iam")
|
|
public ApiResponseDto<MembersDto.EntityData> iam() {
|
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
|
String memberUuid = authentication.getName(); // JWT의 sub 값 (사용자 ID)
|
|
|
|
// Member의 정보를 조회해서 리턴한다.
|
|
return ApiResponseDto.createOK(userInfoService.getUserInfoByUuid(memberUuid));
|
|
}
|
|
}
|