Skip to content

Commit

Permalink
feat: 회원가입 시, 소셜 email 저장 기능 구현 #27 #8
Browse files Browse the repository at this point in the history
  • Loading branch information
PgmJun committed Jan 24, 2024
1 parent f274916 commit c409fe9
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public class GoogleAuthService implements AuthService {
@Override
public Long signUp(LoginRequest request) {
GoogleProfileResponse profileInfo = googleApiCaller.getProfileInfo(request.getToken());
CreateMemberRequest createMemberRequest = CreateMemberRequest.of(profileInfo.getId(), SocialType.GOOGLE,
CreateMemberRequest createMemberRequest = CreateMemberRequest.of(profileInfo.getId(), profileInfo.getEmail(),
SocialType.GOOGLE,
request.getFcmToken());
Long memberId = memberCommandService.registerMember(createMemberRequest);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,36 @@
@Transactional
public class KakaoAuthService implements AuthService {

private final KakaoApiCaller kakaoApiCaller;

private final MemberRepository memberRepository;

private final MemberCommandService memberCommandService;

@Override
public Long signUp(LoginRequest request) {
KakaoProfileResponse profileInfo = kakaoApiCaller.getProfileInfo(request.getToken());
CreateMemberRequest createMemberRequest = CreateMemberRequest.of(profileInfo.getId(), SocialType.KAKAO,
request.getFcmToken());
Long memberId = memberCommandService.registerMember(createMemberRequest);

writeSignUpLog(memberId, SocialType.KAKAO);
return memberId;
}

@Override
public Long login(LoginRequest request) {
KakaoProfileResponse response = kakaoApiCaller.getProfileInfo(request.getToken());
Optional<Member> member = MemberServiceUtils.findOptionalMemberBySocialInfo(
memberRepository, response.getId(),
SocialType.KAKAO);

return loginOrSignUp(request, member);
}

@Override
public void writeSignUpLog(Long memberId, SocialType socialType) {
log.info(String.format(SIGN_UP_LOG_MESSAGE, memberId, socialType));
}
private final KakaoApiCaller kakaoApiCaller;

private final MemberRepository memberRepository;

private final MemberCommandService memberCommandService;

@Override
public Long signUp(LoginRequest request) {
KakaoProfileResponse profileInfo = kakaoApiCaller.getProfileInfo(request.getToken());
CreateMemberRequest createMemberRequest = CreateMemberRequest.of(profileInfo.getId(), profileInfo.getEmail(),
SocialType.KAKAO,
request.getFcmToken());
Long memberId = memberCommandService.registerMember(createMemberRequest);

writeSignUpLog(memberId, SocialType.KAKAO);
return memberId;
}

@Override
public Long login(LoginRequest request) {
KakaoProfileResponse response = kakaoApiCaller.getProfileInfo(request.getToken());
Optional<Member> member = MemberServiceUtils.findOptionalMemberBySocialInfo(
memberRepository, response.getId(),
SocialType.KAKAO);

return loginOrSignUp(request, member);
}

@Override
public void writeSignUpLog(Long memberId, SocialType socialType) {
log.info(String.format(SIGN_UP_LOG_MESSAGE, memberId, socialType));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ public class CreateMemberRequest {

private String socialId;
private SocialType socialType;
private String email;
private String fcmToken;

public static CreateMemberRequest of(String socialId, SocialType socialType, String fcmToken) {
public static CreateMemberRequest of(String socialId, String email, SocialType socialType, String fcmToken) {
return CreateMemberRequest.builder()
.socialId(socialId)
.socialType(socialType)
.email(email)
.fcmToken(fcmToken)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class MemberCommandService {
public Long registerMember(CreateMemberRequest request) {
MemberServiceUtils.validateNotExistsMember(memberRepository, request.getSocialId(), request.getSocialType());
Member member = memberRepository.save(
Member.newInstance(request.getSocialId(), request.getSocialType(), request.getFcmToken()));
Member.newInstance(request.getSocialId(), request.getSocialType(), request.getFcmToken(), request.getEmail()));
pointRepository.save(Point.fromMemberId(member.getId()));
settingRepository.save(Setting.fromMemberId(member.getId()));

Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/nice/petudio/domain/member/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,20 @@ public class Member extends BaseEntity {
@Column(name = "fcm_token", length = 300)
private String fcmToken;

@Column(name = "email", length = 100)
private String email;

@Enumerated(EnumType.STRING)
@Column(name = "member_role", length = 30, nullable = false)
private MemberRole role;

@Embedded
private SocialInfo socialInfo;

public static Member newInstance(String socialId, SocialType socialType, String fcmToken) {
public static Member newInstance(String socialId, SocialType socialType, String fcmToken, String email) {
return Member.builder()
.socialInfo(SocialInfo.of(socialId, socialType))
.email(email)
.fcmToken(fcmToken)
.role(MemberRole.MEMBER)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.nice.petudio.api.controller.member.dto.CreateMemberRequest;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -13,11 +12,8 @@
@NoArgsConstructor
@AllArgsConstructor
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public class GoogleProfileResponse{
public class GoogleProfileResponse {

private String id;

public CreateMemberRequest toSignUpRequest(final CreateMemberRequest request) {
return CreateMemberRequest.of(id, request.getSocialType(), request.getFcmToken());
}
private String email;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,18 @@
public class KakaoProfileResponse {

private String id;
private KakaoAccount kakaoAccount;


public String getEmail() {
return kakaoAccount.getEmail();
}

@AllArgsConstructor
@NoArgsConstructor
@Getter
@JsonIgnoreProperties(ignoreUnknown = true)
class KakaoAccount {
private String email;
}
}
1 change: 1 addition & 0 deletions src/main/resources/sql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ CREATE TABLE `members`
`social_id` varchar(300) NOT NULL,
`social_type` varchar(30) NOT NULL,
`member_role` varchar(30) NOT NULL,
`email` varchar(100) NOT NULL,
`fcm_token` varchar(300) NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`modified_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
Expand Down

0 comments on commit c409fe9

Please sign in to comment.