Skip to content

Commit

Permalink
Merge pull request #29 from YAPP-Github/feat/ISSUE-28
Browse files Browse the repository at this point in the history
del: gender, ageRange field in the member domain
  • Loading branch information
Seokyeong237 authored Jan 26, 2024
2 parents 977194c + a93db9c commit 5111b74
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.fullcar.member.domain.member.Member;
import com.fullcar.member.domain.member.service.MemberIdService;
import com.fullcar.member.domain.member.MemberRepository;
import com.fullcar.member.presentation.auth.dto.KakaoInfoDto;
import com.fullcar.member.presentation.auth.dto.request.AuthRequestDto;
import com.fullcar.member.presentation.auth.dto.response.SocialInfoResponseDto;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -42,20 +41,19 @@ public class KakaoAuthService implements AuthService {
@Transactional
public SocialInfoResponseDto getMemberInfo(AuthRequestDto authRequestDto) {
String deviceToken = authRequestDto.getDeviceToken();
KakaoInfoDto kakaoInfoDto = getKakaoData(authRequestDto.getToken());
SocialId socialId = socialIdService.generateSocialId(kakaoInfoDto.getSocialId());
SocialId socialId = socialIdService.generateSocialId(getKakaoData(authRequestDto.getToken()));
String refreshToken = jwtTokenProvider.generateRefreshToken();

if (memberRepository.existsBySocialId(socialId)) memberRepository.findBySocialIdAndIsDeleted(socialId, false).loginMember(deviceToken, refreshToken);
else createMember(kakaoInfoDto, deviceToken, refreshToken);
else createMember(socialId, deviceToken, refreshToken);

return SocialInfoResponseDto.builder()
.socialId(socialId)
.refreshToken(refreshToken)
.build();
}

private static KakaoInfoDto getKakaoData(String kakaoToken) {
private static String getKakaoData(String kakaoToken) {

try {
HttpHeaders headers = new HttpHeaders();
Expand All @@ -77,13 +75,8 @@ private static KakaoInfoDto getKakaoData(String kakaoToken) {

ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode = objectMapper.readTree(responseBody);
JsonNode kakaoAccount = jsonNode.get("kakao_account");

String socialId = jsonNode.get("id").asText();
String gender = kakaoAccount.get("gender").asText();
String ageRange = kakaoAccount.get("age_range").asText();

return new KakaoInfoDto(socialId, gender, ageRange);
return jsonNode.get("id").asText();
} catch (HttpClientErrorException e) {
throw new NotFoundException(ErrorCode.UNAUTHORIZED_KAKAO_TOKEN);
} catch (JsonProcessingException e) {
Expand All @@ -92,12 +85,10 @@ private static KakaoInfoDto getKakaoData(String kakaoToken) {
}

// 새로운 멤버 생성
private void createMember(KakaoInfoDto kakaoInfoDto, String deviceToken, String refreshToken) {
private void createMember(SocialId socialId, String deviceToken, String refreshToken) {
memberRepository.save(Member.builder()
.id(memberIdService.nextId())
.socialId(socialIdService.generateSocialId(kakaoInfoDto.getSocialId()))
.gender(kakaoInfoDto.getGender())
.ageRange(kakaoInfoDto.getAgeRange())
.socialId(socialId)
.deviceToken(deviceToken)
.refreshToken(refreshToken)
.build());
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/fullcar/member/domain/member/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@ public class Member {
private String nickname;

private String email;

private String gender;

private String ageRange;
private String gender;

@Builder.Default
@Column(name = "onboarding_flag")
Expand Down

This file was deleted.

0 comments on commit 5111b74

Please sign in to comment.