diff --git a/src/main/java/com/diareat/diareat/auth/controller/AuthController.java b/src/main/java/com/diareat/diareat/auth/controller/AuthController.java index 1d01ad3..385b7d2 100644 --- a/src/main/java/com/diareat/diareat/auth/controller/AuthController.java +++ b/src/main/java/com/diareat/diareat/auth/controller/AuthController.java @@ -2,7 +2,7 @@ import com.diareat.diareat.auth.component.JwtTokenProvider; import com.diareat.diareat.auth.service.KakaoAuthService; -import com.diareat.diareat.user.dto.CreateUserDto; +import com.diareat.diareat.user.dto.JoinUserDto; import com.diareat.diareat.user.service.UserService; import com.diareat.diareat.util.api.ApiResponse; import com.diareat.diareat.util.api.ResponseCode; @@ -36,8 +36,8 @@ public ApiResponse> authCheck(@RequestHeader String access // 회원가입 (성공 시 Jwt 토큰 발급) @Operation(summary = "[회원가입] 회원가입 및 토큰 발급", description = "신규 회원가입을 처리하고, 회원가입 성공 시 Jwt 토큰을 발급합니다.") @PostMapping("/join") - public ApiResponse> saveUser(CreateUserDto createUserDto) { - Long userId = userService.saveUser(createUserDto); + public ApiResponse> saveUser(JoinUserDto joinUserDto) { + Long userId = userService.saveUser(kakaoAuthService.createUserDto(joinUserDto)); HashMap map = new HashMap<>(); map.put(userId, jwtTokenProvider.createToken(userId.toString())); return ApiResponse.success(map, ResponseCode.USER_CREATE_SUCCESS.getMessage()); diff --git a/src/main/java/com/diareat/diareat/auth/service/KakaoAuthService.java b/src/main/java/com/diareat/diareat/auth/service/KakaoAuthService.java index ffabdb4..0d22bc4 100644 --- a/src/main/java/com/diareat/diareat/auth/service/KakaoAuthService.java +++ b/src/main/java/com/diareat/diareat/auth/service/KakaoAuthService.java @@ -3,6 +3,8 @@ import com.diareat.diareat.auth.component.KakaoUserInfo; import com.diareat.diareat.auth.dto.KakaoUserInfoResponse; import com.diareat.diareat.user.domain.User; +import com.diareat.diareat.user.dto.CreateUserDto; +import com.diareat.diareat.user.dto.JoinUserDto; import com.diareat.diareat.user.repository.UserRepository; import com.diareat.diareat.util.api.ResponseCode; import com.diareat.diareat.util.exception.UserException; @@ -12,7 +14,7 @@ @RequiredArgsConstructor @Service -public class KakaoAuthService { // 카카오 소셜로그인, 세션 관리는 추후 구현 예정 +public class KakaoAuthService { private final KakaoUserInfo kakaoUserInfo; private final UserRepository userRepository; @@ -23,4 +25,11 @@ public Long isSignedUp(String token) { // 클라이언트가 보낸 token을 이 User user = userRepository.findByKeyCode(userInfo.getId().toString()).orElseThrow(() -> new UserException(ResponseCode.USER_NOT_FOUND)); return user.getId(); } + + @Transactional(readOnly = true) + public CreateUserDto createUserDto(JoinUserDto joinUserDto) { // 카카오로부터 프사 URL, 유저 고유ID를 얻어온 후, 이를 유저가 입력한 정보와 함께 CreateUserDto로 반환 + KakaoUserInfoResponse userInfo = kakaoUserInfo.getUserInfo(joinUserDto.getToken()); + return CreateUserDto.of(joinUserDto.getNickName(), userInfo.getKakaoAccount().getProfile().getProfileImageUrl(), + userInfo.getId().toString(), joinUserDto.getGender(), joinUserDto.getHeight(), joinUserDto.getWeight(), joinUserDto.getAge()); + } }