Skip to content

Commit

Permalink
🩹 Fix: JoinUserDto 도입에 따른 회원가입 로직 일부 개편 (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
win-luck committed Oct 17, 2023
1 parent 2cb0bb1 commit b8c0b18
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -36,8 +36,8 @@ public ApiResponse<HashMap<Long, String>> authCheck(@RequestHeader String access
// 회원가입 (성공 시 Jwt 토큰 발급)
@Operation(summary = "[회원가입] 회원가입 및 토큰 발급", description = "신규 회원가입을 처리하고, 회원가입 성공 시 Jwt 토큰을 발급합니다.")
@PostMapping("/join")
public ApiResponse<HashMap<Long, String>> saveUser(CreateUserDto createUserDto) {
Long userId = userService.saveUser(createUserDto);
public ApiResponse<HashMap<Long, String>> saveUser(JoinUserDto joinUserDto) {
Long userId = userService.saveUser(kakaoAuthService.createUserDto(joinUserDto));
HashMap<Long, String> map = new HashMap<>();
map.put(userId, jwtTokenProvider.createToken(userId.toString()));
return ApiResponse.success(map, ResponseCode.USER_CREATE_SUCCESS.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -12,7 +14,7 @@

@RequiredArgsConstructor
@Service
public class KakaoAuthService { // 카카오 소셜로그인, 세션 관리는 추후 구현 예정
public class KakaoAuthService {

private final KakaoUserInfo kakaoUserInfo;
private final UserRepository userRepository;
Expand All @@ -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());
}
}

0 comments on commit b8c0b18

Please sign in to comment.