Skip to content

Commit

Permalink
fix: 애플 로그인 로직 수정 (#281)
Browse files Browse the repository at this point in the history
* feat: 외부 API 호출 툴 Feign 설정

* feat: Apple 로그인 구현 + 회원가입 Reqeust Provider 추가

* fix: Claims sub 항목 빼서 쓰게 수정

* fix: AuthorizationCode Request 제거

* fix: 애플 로그인 로직 수정

* fix: 애플 로그인 response 수정

* fix: 유저 세부정보 입력 API 수정

* chore: Swagger 수정
  • Loading branch information
sejineer authored Mar 3, 2024
1 parent 1fd9650 commit 157172d
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 43 deletions.
14 changes: 11 additions & 3 deletions src/main/java/com/shallwe/domain/auth/application/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.shallwe.domain.auth.domain.repository.AppleTokenRepository;
import com.shallwe.domain.auth.dto.*;
import com.shallwe.domain.auth.dto.request.*;
import com.shallwe.domain.auth.dto.response.AppleSignInRes;
import com.shallwe.domain.auth.dto.response.AuthRes;
import com.shallwe.domain.auth.exception.*;
import com.shallwe.domain.common.Status;
Expand Down Expand Up @@ -84,7 +85,7 @@ public AuthRes signIn(final SignInReq signInReq) {
}

@Transactional
public AuthRes appleSignIn(AppleSignInReq appleSignInReq) {
public AppleSignInRes appleSignIn(AppleSignInReq appleSignInReq) {
Claims claims = appleJwtUtils.getClaimsBy(appleSignInReq.getIdentityToken());
String providerId = claims.get("sub").toString();

Expand All @@ -110,12 +111,19 @@ public AuthRes appleSignIn(AppleSignInReq appleSignInReq) {
}

User user = optionalUser.get();
boolean isSignUpComplete = true;

if (user.getName() == null || user.getPhoneNumber() == null || user.getAge() == null || user.getGender() == null) {
throw new UnRegisteredUserException();
isSignUpComplete = false;
}

return getUserAuthRes(user);
AuthRes userAuthRes = getUserAuthRes(user);
return AppleSignInRes.builder()
.isSignUpComplete(isSignUpComplete)
.accessToken(userAuthRes.getAccessToken())
.refreshToken(userAuthRes.getRefreshToken())
.tokenType(userAuthRes.getTokenType())
.build();
}

@Transactional
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
package com.shallwe.domain.auth.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;

@Data
public class AppleSignInRes {

@Schema(type = "boolean", example = "true", description = "유저 정보 입력이 완료되었는지 여부를 출력합니다.")
private Boolean isSignUpComplete;

@Schema( type = "string", example = "eyJhbGciOiJIUzUxMiJ9.eyJleHAiOjE2NTI3OTgxOTh9.6CoxHB_siOuz6PxsxHYQCgUT1_QbdyKTUwStQDutEd1-cIIARbQ0cyrnAmpIgi3IBoLRaqK7N1vXO42nYy4g5g" , description="access token 을 출력합니다.")
private String accessToken;

@Schema( type = "string", example = "eyJhbGciOiJIUzUxMiJ9.eyJleHAiOjE2NTI3OTgxOTh9.asdf8as4df865as4dfasdf65_asdfweioufsdoiuf_432jdsaFEWFSDV_sadf" , description="refresh token 을 출력합니다.")
private String refreshToken;

@Schema( type = "string", example ="Bearer", description="권한(Authorization) 값 해더의 명칭을 지정합니다.")
private String tokenType = "Bearer";

@Builder
public AppleSignInRes(Boolean isSignUpComplete, String accessToken, String refreshToken, String tokenType) {
this.isSignUpComplete = isSignUpComplete;
this.accessToken = accessToken;
this.refreshToken = refreshToken;
this.tokenType = tokenType;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import com.shallwe.domain.auth.dto.request.*;
import com.shallwe.domain.auth.dto.response.AppleSignInRes;
import com.shallwe.domain.auth.dto.response.AuthRes;
import com.shallwe.domain.auth.dto.response.SmsResponseDto;
import com.shallwe.global.infrastructure.sms.NaverSmsClient;
Expand Down Expand Up @@ -62,11 +63,11 @@ public ResponseCustom<AuthRes> signIn(

@Operation(summary = "애플 로그인", description = "애플 로그인을 수행합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "애플 로그인 성공", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = AuthRes.class) ) } ),
@ApiResponse(responseCode = "200", description = "애플 로그인 성공", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = AppleSignInRes.class) ) } ),
@ApiResponse(responseCode = "400", description = "애플 로그인 실패", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class) ) } ),
})
@PostMapping(value="/sign-in/apple")
public ResponseCustom<AuthRes> appleSignIn(
public ResponseCustom<AppleSignInRes> appleSignIn(
@Parameter(description = "SignInReq Schema를 확인해주세요.", required = true) @RequestBody AppleSignInReq appleSignInReq
) {
return ResponseCustom.OK(authService.appleSignIn(appleSignInReq));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@
public interface UserService {

UserDetailRes getCurrentUser(UserPrincipal userPrincipal);

DeleteUserRes inactiveCurrentUser(UserPrincipal userPrincipal, PostComplainReq postComplainReq);

SignUpUserRes signUpCurrentUser(UserPrincipal userPrincipal, SignUpUserReq signUpUserReq);

void signUpCurrentUser(UserPrincipal userPrincipal, SignUpUserReq signUpUserReq);
List<SendGiftDetailRes> findSendGiftsByUser(UserPrincipal userPrincipal);

List<ReceiveGiftDetailRes> findReceiveGiftsByUser(UserPrincipal userPrincipal);

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,14 @@ public DeleteUserRes inactiveCurrentUser(final UserPrincipal userPrincipal, fina

@Override
@Transactional
public SignUpUserRes signUpCurrentUser(final UserPrincipal userPrincipal, final SignUpUserReq signUpUserReq) {
public void signUpCurrentUser(final UserPrincipal userPrincipal, final SignUpUserReq signUpUserReq) {
User user = userRepository.findById(userPrincipal.getId()).orElseThrow(InvalidUserException::new);

user.updateName(signUpUserReq.getName());
user.updatePhoneNumber(signUpUserReq.getPhoneNumber());
user.updateMarketingConsent(signUpUserReq.getMarketingConsent());
user.updateAge(signUpUserReq.getAge());
user.updateGender(signUpUserReq.getGender());

return SignUpUserRes.toDto();
}

@Override
Expand All @@ -85,4 +84,4 @@ public List<ReceiveGiftDetailRes> findReceiveGiftsByUser(UserPrincipal userPrinc
.findReservationsByPhoneNumberAndReservationStatusIn(user.getPhoneNumber());
}

}
}
2 changes: 2 additions & 0 deletions src/main/java/com/shallwe/domain/user/dto/SignUpUserReq.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
@Data
public class SignUpUserReq {

@Schema(type = "string", example = "박세진", description = "이름")
private String name;
@Schema(type = "string", example = "01012345678", description = "전화번호")
private String phoneNumber;
@Schema(type = "boolean", example = "true / false", description = "마켓팅 수신 동의 여부")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
Expand Down Expand Up @@ -52,17 +53,18 @@ public ResponseCustom<DeleteUserRes> inactiveCurrentUser(
return ResponseCustom.OK(userServiceImpl.inactiveCurrentUser(userPrincipal, postComplainReq));
}

@Operation(summary = "유저 정보 입력", description = "마켓팅 정보 동의와 나이, 성별 정보를 입력받습니다.")
@Operation(summary = "유저 세부정보 입력", description = "이름, 마켓팅 정보 동의와 나이, 성별 정보를 입력받습니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "유저 정보 입력 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = SignUpUserRes.class))}),
@ApiResponse(responseCode = "200", description = "유저 정보 입력 성공"),
@ApiResponse(responseCode = "400", description = "유저 정보 입력 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}),
})
@PatchMapping
public ResponseCustom<SignUpUserRes> signUpCurrentUser(
public ResponseEntity<Void> signUpCurrentUser(
@Parameter(description = "AccessToken 을 입력해주세요.", required = true) @CurrentUser UserPrincipal userPrincipal,
@Parameter(description = "SignUpUserReq 를 확인해주세요.", required = true) @RequestBody SignUpUserReq signUpUserReq
) {
return ResponseCustom.OK(userServiceImpl.signUpCurrentUser(userPrincipal, signUpUserReq));
userServiceImpl.signUpCurrentUser(userPrincipal, signUpUserReq);
return ResponseEntity.noContent().build();
}

@Operation(summary = "유저가 보낸 선물 조회", description = "유저가 보낸 선물들을 조회합니다.")
Expand All @@ -89,4 +91,4 @@ public ResponseCustom<List<ReceiveGiftDetailRes>> findReceiveGiftsByUser(
return ResponseCustom.OK(userServiceImpl.findReceiveGiftsByUser(userPrincipal));
}

}
}

0 comments on commit 157172d

Please sign in to comment.