From 4a652febc82d7888718560d43b0bb2ab4946867e Mon Sep 17 00:00:00 2001 From: Yeongjin Noh <129354455+nohy6630@users.noreply.github.com> Date: Tue, 21 Nov 2023 19:34:58 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20=EC=98=A8=EB=B3=B4=EB=94=A9=20api=20?= =?UTF-8?q?=EC=8B=A4=EB=AA=85=20=EC=9E=85=EB=A0=A5=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?&=20=EC=86=8C=EC=85=9C=EB=A1=9C=EA=B7=B8=EC=9D=B8=EC=8B=9C=20?= =?UTF-8?q?=EC=8B=A0=EA=B7=9C=EC=9C=A0=EC=A0=80=20=EC=97=AC=EB=B6=80=20?= =?UTF-8?q?=EC=9D=91=EB=8B=B5=20=EC=B6=94=EA=B0=80=20(#92)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix(#89): 온보딩 api 실명 입력 추가 * Fix(#89): 소셜로그인시 신규유저인지 여부 응답 추가 --- .../member/dto/request/OnboardingRequest.java | 4 +++ .../backend/domain/member/entity/Member.java | 8 ++--- .../domain/member/service/MemberService.java | 6 ++-- .../token/dto/response/GetTokenResponse.java | 7 +++-- .../domain/token/service/TokenService.java | 29 ++++++++++--------- 5 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/numberone/backend/domain/member/dto/request/OnboardingRequest.java b/src/main/java/com/numberone/backend/domain/member/dto/request/OnboardingRequest.java index 852a1af0..e5b40d07 100644 --- a/src/main/java/com/numberone/backend/domain/member/dto/request/OnboardingRequest.java +++ b/src/main/java/com/numberone/backend/domain/member/dto/request/OnboardingRequest.java @@ -11,6 +11,10 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class OnboardingRequest { + @Schema(defaultValue = "노영진") + @NotNull(message = "실명 정보는 null일 수 없습니다.") + private String realname; + @Schema(defaultValue = "초롱이") @NotNull(message = "nickname은 null일 수 없습니다.") private String nickname; diff --git a/src/main/java/com/numberone/backend/domain/member/entity/Member.java b/src/main/java/com/numberone/backend/domain/member/entity/Member.java index f4333f17..4153cc70 100644 --- a/src/main/java/com/numberone/backend/domain/member/entity/Member.java +++ b/src/main/java/com/numberone/backend/domain/member/entity/Member.java @@ -102,10 +102,9 @@ public Member(String email, String nickName, String realName, Integer heartCnt, this.longitude = 0D; } - public static Member of(String email, String realName) { + public static Member of(String email) { return Member.builder() .email(email) - .realName(realName) .heartCnt(0) .build(); } @@ -114,7 +113,8 @@ public void updateProfileImageUrl(String imageUrl) { this.profileImageUrl = imageUrl; } - public void setOnboardingData(String nickName, String fcmToken) { + public void setOnboardingData(String realName, String nickName, String fcmToken) { + this.realName = realName; this.nickName = nickName; this.fcmToken = fcmToken; } @@ -134,7 +134,7 @@ public void updateGps(double latitude, double longitude, String location) { this.lastlyUpdatedLocationAt = LocalDateTime.now(); } - public void updateSafety(Boolean isSafety){ + public void updateSafety(Boolean isSafety) { this.isSafety = isSafety; } } diff --git a/src/main/java/com/numberone/backend/domain/member/service/MemberService.java b/src/main/java/com/numberone/backend/domain/member/service/MemberService.java index 412be02c..99bb96e2 100644 --- a/src/main/java/com/numberone/backend/domain/member/service/MemberService.java +++ b/src/main/java/com/numberone/backend/domain/member/service/MemberService.java @@ -41,8 +41,8 @@ public Member findByEmail(String email) { } @Transactional - public void create(String email, String realName) { - memberRepository.save(Member.of(email, realName)); + public void create(String email) { + memberRepository.save(Member.of(email)); } @Transactional @@ -50,7 +50,7 @@ public void initMemberData(String email, OnboardingRequest onboardingRequest) { Member member = memberRepository.findByEmail(email) .orElseThrow(NotFoundMemberException::new); notificationDisasterRepository.deleteAllByMemberId(member.getId()); - member.setOnboardingData(onboardingRequest.getNickname(), onboardingRequest.getFcmToken()); + member.setOnboardingData(onboardingRequest.getRealname(),onboardingRequest.getNickname(), onboardingRequest.getFcmToken()); notificationRegionRepository.deleteAllByMemberId(member.getId()); for (OnboardingAddress address : onboardingRequest.getAddresses()) { notificationRegionRepository.save(NotificationRegion.of( diff --git a/src/main/java/com/numberone/backend/domain/token/dto/response/GetTokenResponse.java b/src/main/java/com/numberone/backend/domain/token/dto/response/GetTokenResponse.java index 9820040b..39992a95 100644 --- a/src/main/java/com/numberone/backend/domain/token/dto/response/GetTokenResponse.java +++ b/src/main/java/com/numberone/backend/domain/token/dto/response/GetTokenResponse.java @@ -10,17 +10,20 @@ public class GetTokenResponse { private String accessToken; private String refreshToken; + private Boolean isNewMember; @Builder - public GetTokenResponse(String accessToken, String refreshToken) { + public GetTokenResponse(String accessToken, String refreshToken, Boolean isNewMember) { this.accessToken = accessToken; this.refreshToken = refreshToken; + this.isNewMember = isNewMember; } - public static GetTokenResponse of(String accessToken, String refreshToken) { + public static GetTokenResponse of(String accessToken, String refreshToken, Boolean isNewMember) { return GetTokenResponse.builder() .accessToken(accessToken) .refreshToken(refreshToken) + .isNewMember(isNewMember) .build(); } } diff --git a/src/main/java/com/numberone/backend/domain/token/service/TokenService.java b/src/main/java/com/numberone/backend/domain/token/service/TokenService.java index f81105eb..c618f674 100644 --- a/src/main/java/com/numberone/backend/domain/token/service/TokenService.java +++ b/src/main/java/com/numberone/backend/domain/token/service/TokenService.java @@ -44,11 +44,11 @@ public GetTokenResponse loginKakao(GetTokenRequest tokenRequest) { try { ResponseEntity response = restTemplate.exchange(kakaoProperties.getUser_api_url(), HttpMethod.GET, new HttpEntity<>(null, headers), KakaoInfoResponse.class); String email = response.getBody().getKakao_account().getEmail(); - String realName = "실명을 가져올 수 없습니다."; - if(response.getBody().getKakao_account().getProfile() != null){ - realName = response.getBody().getKakao_account().getProfile().getNickname(); - } - return getTokenResponse(email, realName); +// String realName = "실명을 가져올 수 없습니다."; +// if(response.getBody().getKakao_account().getProfile() != null){ +// realName = response.getBody().getKakao_account().getProfile().getNickname(); +// } + return getTokenResponse(email); } catch (Exception e) { throw new BadRequestSocialTokenException(); } @@ -63,9 +63,9 @@ public GetTokenResponse loginNaver(GetTokenRequest tokenRequest) { try { ResponseEntity response = restTemplate.exchange(naverProperties.getUser_api_url(), HttpMethod.GET, new HttpEntity<>(null, headers), NaverInfoResponse.class); String email = response.getBody().getResponse().getEmail(); - String realName = Optional.ofNullable(response.getBody().getResponse().getName()) - .orElse("실명을 가져올 수 없습니다."); - return getTokenResponse(email, realName); +// String realName = Optional.ofNullable(response.getBody().getResponse().getName()) +// .orElse("실명을 가져올 수 없습니다."); + return getTokenResponse(email); } catch (Exception e) { throw new BadRequestSocialTokenException(); } @@ -85,18 +85,21 @@ public RefreshTokenResponse refresh(RefreshTokenRequest tokenRequest) { return RefreshTokenResponse.of(newAccessToken, newRefreshToken); } - private GetTokenResponse getTokenResponse(String email, String realname) { - if (!memberRepository.existsByEmail(email)) - memberService.create(email, realname); + private GetTokenResponse getTokenResponse(String email) { + Boolean isNewMember = false; + if (!memberRepository.existsByEmail(email)) { + memberService.create(email); + isNewMember = true; + } if (tokenRepository.existsById(email)) { Token token = tokenRepository.findById(email) .orElseThrow(WrongAccessTokenException::new); - return GetTokenResponse.of(token.getAccessToken(), token.getRefreshToken()); + return GetTokenResponse.of(token.getAccessToken(), token.getRefreshToken(), isNewMember); } else { String refreshToken = jwtUtil.createToken(email, refreshPeroid); String accessToken = jwtUtil.createToken(email, accessPeroid); Token token = tokenRepository.save(Token.of(email, accessToken, refreshToken)); - return GetTokenResponse.of(token.getAccessToken(), token.getRefreshToken()); + return GetTokenResponse.of(token.getAccessToken(), token.getRefreshToken(), isNewMember); } } }