Skip to content

Commit

Permalink
Fix: 온보딩 api 실명 입력 추가 & 소셜로그인시 신규유저 여부 응답 추가 (#92)
Browse files Browse the repository at this point in the history
* Fix(#89): 온보딩 api 실명 입력 추가

* Fix(#89): 소셜로그인시 신규유저인지 여부 응답 추가
  • Loading branch information
nohy6630 authored Nov 21, 2023
1 parent 2a3d488 commit 4a652fe
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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;
}
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ 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
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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public GetTokenResponse loginKakao(GetTokenRequest tokenRequest) {
try {
ResponseEntity<KakaoInfoResponse> 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();
}
Expand All @@ -63,9 +63,9 @@ public GetTokenResponse loginNaver(GetTokenRequest tokenRequest) {
try {
ResponseEntity<NaverInfoResponse> 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();
}
Expand All @@ -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);
}
}
}

0 comments on commit 4a652fe

Please sign in to comment.