From 157172d4b16424993168b9a7d36b10ef34e2cc3d Mon Sep 17 00:00:00 2001 From: Sejin Park <95167215+sejineer@users.noreply.github.com> Date: Mon, 4 Mar 2024 04:11:41 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=95=A0=ED=94=8C=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95=20(#281)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 외부 API 호출 툴 Feign 설정 * feat: Apple 로그인 구현 + 회원가입 Reqeust Provider 추가 * fix: Claims sub 항목 빼서 쓰게 수정 * fix: AuthorizationCode Request 제거 * fix: 애플 로그인 로직 수정 * fix: 애플 로그인 response 수정 * fix: 유저 세부정보 입력 API 수정 * chore: Swagger 수정 --- .../domain/auth/application/AuthService.java | 14 ++++++++--- .../auth/dto/request/AppleSignUpReq.java | 24 ------------------- .../auth/dto/response/AppleSignInRes.java | 20 ++++++++++++++++ .../auth/presentation/AuthController.java | 5 ++-- .../domain/user/application/UserService.java | 6 +---- .../user/application/UserServiceImpl.java | 7 +++--- .../domain/user/dto/SignUpUserReq.java | 2 ++ .../user/presentation/UserController.java | 12 ++++++---- 8 files changed, 47 insertions(+), 43 deletions(-) delete mode 100644 src/main/java/com/shallwe/domain/auth/dto/request/AppleSignUpReq.java diff --git a/src/main/java/com/shallwe/domain/auth/application/AuthService.java b/src/main/java/com/shallwe/domain/auth/application/AuthService.java index 888dbe97..46786932 100644 --- a/src/main/java/com/shallwe/domain/auth/application/AuthService.java +++ b/src/main/java/com/shallwe/domain/auth/application/AuthService.java @@ -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; @@ -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(); @@ -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 diff --git a/src/main/java/com/shallwe/domain/auth/dto/request/AppleSignUpReq.java b/src/main/java/com/shallwe/domain/auth/dto/request/AppleSignUpReq.java deleted file mode 100644 index e503f366..00000000 --- a/src/main/java/com/shallwe/domain/auth/dto/request/AppleSignUpReq.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.shallwe.domain.auth.dto.request; - - -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.Email; -import lombok.Data; - -@Data -public class AppleSignUpReq { - - @Schema(type = "String", description = "애플 로그인을 위한 IdentityToken") - private String identityToken; - - @Schema(type = "String", description = "애플 로그인을 위한 AuthorizationCode") - private String authorizationCode; - - @Schema( type = "string", example = "string", description="사용자 이름 입니다.") - private String name; - - @Schema( type = "string", example = "string@aa.bb", description="계정 이메일 입니다.") - @Email - private String email; - -} \ No newline at end of file diff --git a/src/main/java/com/shallwe/domain/auth/dto/response/AppleSignInRes.java b/src/main/java/com/shallwe/domain/auth/dto/response/AppleSignInRes.java index 78501615..a2a165b9 100644 --- a/src/main/java/com/shallwe/domain/auth/dto/response/AppleSignInRes.java +++ b/src/main/java/com/shallwe/domain/auth/dto/response/AppleSignInRes.java @@ -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; + } + } diff --git a/src/main/java/com/shallwe/domain/auth/presentation/AuthController.java b/src/main/java/com/shallwe/domain/auth/presentation/AuthController.java index 5acb8bd7..7c5d1108 100644 --- a/src/main/java/com/shallwe/domain/auth/presentation/AuthController.java +++ b/src/main/java/com/shallwe/domain/auth/presentation/AuthController.java @@ -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; @@ -62,11 +63,11 @@ public ResponseCustom 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 appleSignIn( + public ResponseCustom appleSignIn( @Parameter(description = "SignInReq Schema를 확인해주세요.", required = true) @RequestBody AppleSignInReq appleSignInReq ) { return ResponseCustom.OK(authService.appleSignIn(appleSignInReq)); diff --git a/src/main/java/com/shallwe/domain/user/application/UserService.java b/src/main/java/com/shallwe/domain/user/application/UserService.java index e05134d6..4f8e786e 100644 --- a/src/main/java/com/shallwe/domain/user/application/UserService.java +++ b/src/main/java/com/shallwe/domain/user/application/UserService.java @@ -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 findSendGiftsByUser(UserPrincipal userPrincipal); - List findReceiveGiftsByUser(UserPrincipal userPrincipal); } diff --git a/src/main/java/com/shallwe/domain/user/application/UserServiceImpl.java b/src/main/java/com/shallwe/domain/user/application/UserServiceImpl.java index e6452c94..72497c7d 100644 --- a/src/main/java/com/shallwe/domain/user/application/UserServiceImpl.java +++ b/src/main/java/com/shallwe/domain/user/application/UserServiceImpl.java @@ -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 @@ -85,4 +84,4 @@ public List findReceiveGiftsByUser(UserPrincipal userPrinc .findReservationsByPhoneNumberAndReservationStatusIn(user.getPhoneNumber()); } -} +} \ No newline at end of file diff --git a/src/main/java/com/shallwe/domain/user/dto/SignUpUserReq.java b/src/main/java/com/shallwe/domain/user/dto/SignUpUserReq.java index 2f91e8a4..8baad276 100644 --- a/src/main/java/com/shallwe/domain/user/dto/SignUpUserReq.java +++ b/src/main/java/com/shallwe/domain/user/dto/SignUpUserReq.java @@ -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 = "마켓팅 수신 동의 여부") diff --git a/src/main/java/com/shallwe/domain/user/presentation/UserController.java b/src/main/java/com/shallwe/domain/user/presentation/UserController.java index e5a3c658..4d9d85d6 100644 --- a/src/main/java/com/shallwe/domain/user/presentation/UserController.java +++ b/src/main/java/com/shallwe/domain/user/presentation/UserController.java @@ -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; @@ -52,17 +53,18 @@ public ResponseCustom 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 signUpCurrentUser( + public ResponseEntity 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 = "유저가 보낸 선물들을 조회합니다.") @@ -89,4 +91,4 @@ public ResponseCustom> findReceiveGiftsByUser( return ResponseCustom.OK(userServiceImpl.findReceiveGiftsByUser(userPrincipal)); } -} +} \ No newline at end of file