feat: myinfo
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.kamco.cd.kamcoback.user.service;
|
||||
|
||||
import com.kamco.cd.kamcoback.members.dto.MembersDto;
|
||||
import com.kamco.cd.kamcoback.postgres.core.MembersCoreService;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
@Transactional(readOnly = true)
|
||||
public class UserInfoService {
|
||||
|
||||
private final MembersCoreService membersCoreService;
|
||||
|
||||
/**
|
||||
* 회원정보 조회 (단건 ) by uuid
|
||||
*
|
||||
* @param uuid
|
||||
* @return
|
||||
*/
|
||||
public MembersDto.EntityData getUserInfoByUuid(@NotNull String uuid) {
|
||||
return membersCoreService.getUserInfoByUuid(uuid);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user