Skip to content

Commit 157172d

Browse files
authored
fix: 애플 로그인 로직 수정 (#281)
* feat: 외부 API 호출 툴 Feign 설정 * feat: Apple 로그인 구현 + 회원가입 Reqeust Provider 추가 * fix: Claims sub 항목 빼서 쓰게 수정 * fix: AuthorizationCode Request 제거 * fix: 애플 로그인 로직 수정 * fix: 애플 로그인 response 수정 * fix: 유저 세부정보 입력 API 수정 * chore: Swagger 수정
1 parent 1fd9650 commit 157172d

File tree

8 files changed

+47
-43
lines changed

8 files changed

+47
-43
lines changed

src/main/java/com/shallwe/domain/auth/application/AuthService.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.shallwe.domain.auth.domain.repository.AppleTokenRepository;
77
import com.shallwe.domain.auth.dto.*;
88
import com.shallwe.domain.auth.dto.request.*;
9+
import com.shallwe.domain.auth.dto.response.AppleSignInRes;
910
import com.shallwe.domain.auth.dto.response.AuthRes;
1011
import com.shallwe.domain.auth.exception.*;
1112
import com.shallwe.domain.common.Status;
@@ -84,7 +85,7 @@ public AuthRes signIn(final SignInReq signInReq) {
8485
}
8586

8687
@Transactional
87-
public AuthRes appleSignIn(AppleSignInReq appleSignInReq) {
88+
public AppleSignInRes appleSignIn(AppleSignInReq appleSignInReq) {
8889
Claims claims = appleJwtUtils.getClaimsBy(appleSignInReq.getIdentityToken());
8990
String providerId = claims.get("sub").toString();
9091

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

112113
User user = optionalUser.get();
114+
boolean isSignUpComplete = true;
113115

114116
if (user.getName() == null || user.getPhoneNumber() == null || user.getAge() == null || user.getGender() == null) {
115-
throw new UnRegisteredUserException();
117+
isSignUpComplete = false;
116118
}
117119

118-
return getUserAuthRes(user);
120+
AuthRes userAuthRes = getUserAuthRes(user);
121+
return AppleSignInRes.builder()
122+
.isSignUpComplete(isSignUpComplete)
123+
.accessToken(userAuthRes.getAccessToken())
124+
.refreshToken(userAuthRes.getRefreshToken())
125+
.tokenType(userAuthRes.getTokenType())
126+
.build();
119127
}
120128

121129
@Transactional

src/main/java/com/shallwe/domain/auth/dto/request/AppleSignUpReq.java

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
package com.shallwe.domain.auth.dto.response;
22

3+
import io.swagger.v3.oas.annotations.media.Schema;
4+
import lombok.Builder;
35
import lombok.Data;
46

57
@Data
68
public class AppleSignInRes {
79

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

13+
@Schema( type = "string", example = "eyJhbGciOiJIUzUxMiJ9.eyJleHAiOjE2NTI3OTgxOTh9.6CoxHB_siOuz6PxsxHYQCgUT1_QbdyKTUwStQDutEd1-cIIARbQ0cyrnAmpIgi3IBoLRaqK7N1vXO42nYy4g5g" , description="access token 을 출력합니다.")
14+
private String accessToken;
15+
16+
@Schema( type = "string", example = "eyJhbGciOiJIUzUxMiJ9.eyJleHAiOjE2NTI3OTgxOTh9.asdf8as4df865as4dfasdf65_asdfweioufsdoiuf_432jdsaFEWFSDV_sadf" , description="refresh token 을 출력합니다.")
17+
private String refreshToken;
18+
19+
@Schema( type = "string", example ="Bearer", description="권한(Authorization) 값 해더의 명칭을 지정합니다.")
20+
private String tokenType = "Bearer";
21+
22+
@Builder
23+
public AppleSignInRes(Boolean isSignUpComplete, String accessToken, String refreshToken, String tokenType) {
24+
this.isSignUpComplete = isSignUpComplete;
25+
this.accessToken = accessToken;
26+
this.refreshToken = refreshToken;
27+
this.tokenType = tokenType;
28+
}
29+
1030
}

src/main/java/com/shallwe/domain/auth/presentation/AuthController.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33

44
import com.shallwe.domain.auth.dto.request.*;
5+
import com.shallwe.domain.auth.dto.response.AppleSignInRes;
56
import com.shallwe.domain.auth.dto.response.AuthRes;
67
import com.shallwe.domain.auth.dto.response.SmsResponseDto;
78
import com.shallwe.global.infrastructure.sms.NaverSmsClient;
@@ -62,11 +63,11 @@ public ResponseCustom<AuthRes> signIn(
6263

6364
@Operation(summary = "애플 로그인", description = "애플 로그인을 수행합니다.")
6465
@ApiResponses(value = {
65-
@ApiResponse(responseCode = "200", description = "애플 로그인 성공", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = AuthRes.class) ) } ),
66+
@ApiResponse(responseCode = "200", description = "애플 로그인 성공", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = AppleSignInRes.class) ) } ),
6667
@ApiResponse(responseCode = "400", description = "애플 로그인 실패", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class) ) } ),
6768
})
6869
@PostMapping(value="/sign-in/apple")
69-
public ResponseCustom<AuthRes> appleSignIn(
70+
public ResponseCustom<AppleSignInRes> appleSignIn(
7071
@Parameter(description = "SignInReq Schema를 확인해주세요.", required = true) @RequestBody AppleSignInReq appleSignInReq
7172
) {
7273
return ResponseCustom.OK(authService.appleSignIn(appleSignInReq));

src/main/java/com/shallwe/domain/user/application/UserService.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,9 @@
99
public interface UserService {
1010

1111
UserDetailRes getCurrentUser(UserPrincipal userPrincipal);
12-
1312
DeleteUserRes inactiveCurrentUser(UserPrincipal userPrincipal, PostComplainReq postComplainReq);
14-
15-
SignUpUserRes signUpCurrentUser(UserPrincipal userPrincipal, SignUpUserReq signUpUserReq);
16-
13+
void signUpCurrentUser(UserPrincipal userPrincipal, SignUpUserReq signUpUserReq);
1714
List<SendGiftDetailRes> findSendGiftsByUser(UserPrincipal userPrincipal);
18-
1915
List<ReceiveGiftDetailRes> findReceiveGiftsByUser(UserPrincipal userPrincipal);
2016

2117
}

src/main/java/com/shallwe/domain/user/application/UserServiceImpl.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,14 @@ public DeleteUserRes inactiveCurrentUser(final UserPrincipal userPrincipal, fina
5858

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

64+
user.updateName(signUpUserReq.getName());
6465
user.updatePhoneNumber(signUpUserReq.getPhoneNumber());
6566
user.updateMarketingConsent(signUpUserReq.getMarketingConsent());
6667
user.updateAge(signUpUserReq.getAge());
6768
user.updateGender(signUpUserReq.getGender());
68-
69-
return SignUpUserRes.toDto();
7069
}
7170

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

88-
}
87+
}

src/main/java/com/shallwe/domain/user/dto/SignUpUserReq.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
@Data
88
public class SignUpUserReq {
99

10+
@Schema(type = "string", example = "박세진", description = "이름")
11+
private String name;
1012
@Schema(type = "string", example = "01012345678", description = "전화번호")
1113
private String phoneNumber;
1214
@Schema(type = "boolean", example = "true / false", description = "마켓팅 수신 동의 여부")

src/main/java/com/shallwe/domain/user/presentation/UserController.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import io.swagger.v3.oas.annotations.responses.ApiResponses;
1616
import io.swagger.v3.oas.annotations.tags.Tag;
1717
import lombok.RequiredArgsConstructor;
18+
import org.springframework.http.ResponseEntity;
1819
import org.springframework.web.bind.annotation.*;
1920

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

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

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

92-
}
94+
}

0 commit comments

Comments
 (0)