Skip to content

Commit

Permalink
Merge pull request #23 from YAPP-Github/feature/#22
Browse files Browse the repository at this point in the history
feat: 프로필 이미지 기능 추가 및 카카오 연동
  • Loading branch information
CChuYong authored Jul 13, 2024
2 parents 154945e + 06345d8 commit 48adc1d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public record KakaoLoginInfo(
String id,
String nickname,
String email
String email,
String profileImageUrl
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ public record MemberResponse(
String memberId,

@Schema(description = "사용자 이름", example = "송영민")
String name
String name,

@Schema(description = "프로필 이미지 URL", example = "https://mafoo.kr/profile.jpg")
String profileImageUrl
) {
public static MemberResponse fromEntity(MemberEntity memberEntity) {
return new MemberResponse(
memberEntity.getId(),
memberEntity.getName()
memberEntity.getName(),
memberEntity.getProfileImageUrl()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public class MemberEntity implements Persistable<String> {
@Column("created_at")
private LocalDateTime createdAt;

@Column("profile_img_url")
private String profileImageUrl;

@Transient
private boolean isNew = false;

Expand All @@ -46,10 +49,11 @@ public int hashCode() {
return id.hashCode();
}

public static MemberEntity newMember(String id, String name) {
public static MemberEntity newMember(String id, String name, String profileImageUrl) {
MemberEntity member = new MemberEntity();
member.id = id;
member.name = name;
member.profileImageUrl = profileImageUrl;
member.isNew = true;
return member;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public Mono<AuthToken> loginWithKakao(String code) {
.flatMap(kakaoLoginInfo -> getOrCreateMember(
IdentityProvider.KAKAO,
kakaoLoginInfo.id(),
kakaoLoginInfo.nickname()
kakaoLoginInfo.nickname(),
kakaoLoginInfo.profileImageUrl()
));
}

Expand All @@ -44,20 +45,20 @@ public Mono<AuthToken> loginWithRefreshToken(String refreshToken){
});
}

private Mono<AuthToken> getOrCreateMember(IdentityProvider provider, String id, String username) {
private Mono<AuthToken> getOrCreateMember(IdentityProvider provider, String id, String username, String profileImageUrl) {
return socialMemberRepository
.findByIdentityProviderAndId(provider, id)
.switchIfEmpty(createNewSocialMember(provider, id, username))
.switchIfEmpty(createNewSocialMember(provider, id, username, profileImageUrl))
.map(socialMember -> {
String accessToken = jwtTokenService.generateAccessToken(socialMember.getMemberId());
String refreshToken = jwtTokenService.generateRefreshToken(socialMember.getMemberId());
return new AuthToken(accessToken, refreshToken);
});
}

private Mono<SocialMemberEntity> createNewSocialMember(IdentityProvider provider, String id, String username) {
private Mono<SocialMemberEntity> createNewSocialMember(IdentityProvider provider, String id, String username, String profileImageUrl) {
return memberService
.createNewMember(username)
.createNewMember(username, profileImageUrl)
.flatMap(newMember -> socialMemberRepository.save(
SocialMemberEntity.newSocialMember(provider, id, newMember.getId())
));
Expand Down Expand Up @@ -95,7 +96,8 @@ private Mono<KakaoLoginInfo> getUserInfoWithKakaoToken(String kakaoToken){
.map(map -> new KakaoLoginInfo(
String.valueOf(map.get("id")),
(String) ((LinkedHashMap)map.get("properties")).get("nickname"),
(String) map.get("kakao_account.email")
(String) map.get("kakao_account.email"),
(String) ((LinkedHashMap)map.get("properties")).get("profile_image")
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public Mono<MemberEntity> getMemberByMemberId(String memberId) {
.switchIfEmpty(Mono.error(new MemberNotFoundException()));
}

public Mono<MemberEntity> createNewMember(String username) {
MemberEntity memberEntity = MemberEntity.newMember(IdGenerator.generate(), username);
public Mono<MemberEntity> createNewMember(String username, String profileImageUrl) {
MemberEntity memberEntity = MemberEntity.newMember(IdGenerator.generate(), username, profileImageUrl);
return memberRepository.save(memberEntity);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE member ADD COLUMN `profile_img_url` VARCHAR(255) DEFAULT NULL AFTER `name`;

0 comments on commit 48adc1d

Please sign in to comment.