Skip to content

Commit

Permalink
Merge pull request #310 from WE-ARE-RACCOONS/RAC-422
Browse files Browse the repository at this point in the history
RAC-422 feat : ํ† ํฐ ๊ธฐ๋ฐ˜ ๋กœ๊ทธ์ธ ์ถ”๊ฐ€
  • Loading branch information
ywj9811 authored Aug 17, 2024
2 parents c53a868 + a8b6255 commit 5dcc64b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.postgraduate.domain.auth.application.dto.req;

public record TokenRequest(String accessToken) {
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.postgraduate.domain.auth.application.usecase.oauth;

import com.postgraduate.domain.auth.application.dto.req.CodeRequest;
import com.postgraduate.domain.auth.application.dto.req.TokenRequest;
import com.postgraduate.domain.auth.application.dto.res.AuthUserResponse;

public interface SignInUseCase {
AuthUserResponse getUser(CodeRequest request);

AuthUserResponse getDevUser(CodeRequest codeRequest);

AuthUserResponse getUserWithToken(TokenRequest request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private KakaoUserInfoResponse getKakaoUserInfoResponse(MultiValueMap<String, Str
}
}

private KakaoUserInfoResponse getUserInfo(String accessToken) {
public KakaoUserInfoResponse getUserInfo(String accessToken) {
try {
return webClient.get()
.uri(USER_INFO_URI)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.postgraduate.domain.auth.application.usecase.oauth.kakao;

import com.postgraduate.domain.auth.application.dto.req.CodeRequest;
import com.postgraduate.domain.auth.application.dto.req.TokenRequest;
import com.postgraduate.domain.auth.application.dto.res.AuthUserResponse;
import com.postgraduate.domain.auth.application.dto.res.KakaoUserInfoResponse;
import com.postgraduate.domain.auth.application.mapper.AuthMapper;
Expand All @@ -12,12 +13,14 @@
import com.postgraduate.domain.user.user.exception.UserNotFoundException;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
@Transactional
@Slf4j
public class KakaoSignInUseCase implements SignInUseCase {
private final KakaoAccessTokenUseCase kakaoTokenUseCase;
private final UserGetService userGetService;
Expand All @@ -35,11 +38,19 @@ public AuthUserResponse getDevUser(CodeRequest codeRequest) {
return getAuthUserResponse(userInfo);
}

@Override
public AuthUserResponse getUserWithToken(TokenRequest request) {
KakaoUserInfoResponse userInfo = kakaoTokenUseCase.getUserInfo(request.accessToken());
log.info("user : {}", userInfo.id());
return getAuthUserResponse(userInfo);
}

@NotNull
private AuthUserResponse getAuthUserResponse(KakaoUserInfoResponse userInfo) {
Long socialId = userInfo.id();
try {
User user = userGetService.bySocialId(socialId);
log.info("check user {} ", user.getUserId());
checkDelete(user);
return AuthMapper.mapToAuthUser(user, socialId);
} catch (UserNotFoundException e) {
Expand All @@ -50,7 +61,7 @@ private AuthUserResponse getAuthUserResponse(KakaoUserInfoResponse userInfo) {
private void checkDelete(User user) {
if (user.isDelete()) {
if (user.isRealDelete())
throw new DeletedUserException();
throw new DeletedUserException(); //todo : ๋‹ค์‹œ ํƒˆํ‡ด ์ฒ˜๋ฆฌ ํ•„์š” (์นด์นด์˜ค ๊ณ„์ •๊ณผ ๋Š๊ธฐ)
userUpdateService.updateRestore(user);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ public class AuthController {
private final QuitManageUseCase quitManageUseCase;
private final JwtUseCase jwtUseCase;

@PostMapping("/login/token/{provider}")
@Operation(summary = "์†Œ์…œ ๋กœ๊ทธ์ธ", description = "ํšŒ์›์ธ ๊ฒฝ์šฐ JWT๋ฅผ, ํšŒ์›์ด ์•„๋‹Œ ๊ฒฝ์šฐ socialId๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค(ํšŒ์›๊ฐ€์ž…์€ ์ง„ํ–‰ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค).")
public ResponseEntity<ResponseDto<AuthResponse>> authLoginWithToken(@RequestBody @Valid TokenRequest request, @PathVariable Provider provider) {
SignInUseCase signInUseCase = selectOauth.selectSignIn(provider);
AuthUserResponse authUser = signInUseCase.getUserWithToken(request);
if (authUser.user() == null)
return ResponseEntity.ok(create(AUTH_NONE.getCode(), NOT_REGISTERED_USER.getMessage(), authUser));
JwtTokenResponse jwtToken = jwtUseCase.signIn(authUser.user());
return ResponseEntity.ok(create(AUTH_ALREADY.getCode(), SUCCESS_AUTH.getMessage(), jwtToken));
}

@PostMapping("/login/{provider}")
@Operation(summary = "์†Œ์…œ ๋กœ๊ทธ์ธ", description = "ํšŒ์›์ธ ๊ฒฝ์šฐ JWT๋ฅผ, ํšŒ์›์ด ์•„๋‹Œ ๊ฒฝ์šฐ socialId๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค(ํšŒ์›๊ฐ€์ž…์€ ์ง„ํ–‰ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค).")
public ResponseEntity<ResponseDto<AuthResponse>> authLogin(@RequestBody @Valid CodeRequest request, @PathVariable Provider provider) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ public class BizppurioSend {
private final ObjectMapper objectMapper;
private final WebClient webClient;
private final SlackErrorMessage slackErrorMessage;
private static final String DEV = "DEV";

@Value("${bizppurio.message}")
private String messageUrl;
@Value("${bizppurio.status}")
private String status;

protected void sendMessageWithExceptionHandling(Supplier<CommonRequest> messageSupplier) {
if (status.equals(DEV))
return;
try {
CommonRequest commonRequest = messageSupplier.get();
String accessToken = bizppurioAuth.getAuth();
Expand Down

0 comments on commit 5dcc64b

Please sign in to comment.