-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Feat: AuthService 구현 및 UserController에 추가 (#31)
- Loading branch information
Showing
3 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/main/java/com/diareat/diareat/auth/KakaoAuthService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.diareat.diareat.auth; | ||
|
||
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.repository.UserRepository; | ||
import com.diareat.diareat.util.api.ResponseCode; | ||
import com.diareat.diareat.util.exception.UserException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class KakaoAuthService { // 카카오 소셜로그인, 세션 관리는 추후 구현 예정 | ||
|
||
private final KakaoUserInfo kakaoUserInfo; | ||
private final UserRepository userRepository; | ||
|
||
@Transactional(readOnly = true) | ||
public Long isSignedUp(String token) { // 클라이언트가 보낸 token을 이용해 카카오 API에 유저 정보를 요청, 유저가 존재하지 않으면 예외 발생, 존재하면 회원번호 반환 | ||
KakaoUserInfoResponse userInfo = kakaoUserInfo.getUserInfo(token); | ||
User user = userRepository.findByKeyCode(userInfo.getId().toString()).orElseThrow(() -> new UserException(ResponseCode.USER_NOT_FOUND)); | ||
return user.getId(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters