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); } } }