Skip to content

Commit

Permalink
fix : 기본 프로필 이미지 값 주입 변경(userInfoEntity는 빈이 아니라서 주입이 안됨)
Browse files Browse the repository at this point in the history
  • Loading branch information
wjdwnsdnjs13 committed Aug 29, 2024
1 parent f3484e6 commit aed3851
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.depromeet.spot.infrastructure.jpa.oauth.entity.KakaoTokenEntity;
import org.depromeet.spot.infrastructure.jpa.oauth.entity.KakaoUserInfoEntity;
import org.depromeet.spot.usecase.port.out.oauth.OauthRepository;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatusCode;
import org.springframework.stereotype.Repository;
Expand All @@ -25,6 +26,9 @@
@RequiredArgsConstructor
public class OauthRepositoryImpl implements OauthRepository {

@Value("${aws.s3.basicProfileImageUrl}")
private String BASIC_PROFILE_IMAGE_URL;

private final String BEARER = "Bearer";
private final OauthProperties properties;

Expand Down Expand Up @@ -138,16 +142,17 @@ public Member getKakaoRegisterUserInfo(String accessToken, Member member) {
KakaoUserInfoEntity userInfo = getKakaoUserInfo(accessToken);

// 회원가입 시 받은 정보를 바탕으로 member로 변환해서 리턴.
return userInfo.toKakaoDomain(member);
return userInfo.toKakaoDomain(member, BASIC_PROFILE_IMAGE_URL);
}

@Override
public Member getOauthRegisterUserInfo(String accessToken, Member member) {
switch (member.getSnsProvider()) {
case KAKAO:
return getKakaoUserInfo(accessToken).toKakaoDomain(member);
return getKakaoUserInfo(accessToken).toKakaoDomain(member, BASIC_PROFILE_IMAGE_URL);
default:
return getGoogleUserInfo(accessToken).toGoogleDomain(member);
return getGoogleUserInfo(accessToken)
.toGoogleDomain(member, BASIC_PROFILE_IMAGE_URL);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.depromeet.spot.domain.member.enums.MemberRole;
import org.depromeet.spot.domain.member.enums.SnsProvider;
import org.depromeet.spot.infrastructure.jpa.common.entity.BaseEntity;
import org.springframework.beans.factory.annotation.Value;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand All @@ -17,9 +16,6 @@
@JsonIgnoreProperties(ignoreUnknown = true)
public class GoogleUserInfoEntity extends BaseEntity {

@Value("${aws.s3.basicProfileImageUrl}")
private String BASIC_PROFILE_IMAGE_URL;

// 구글 로그인은 sub라는 이름으로 id값을 줌.
// 구글의 sub 값은 Long 타입을 넘어감.
// BigInteger로 처리하거나 String으로 처리해야함.
Expand All @@ -38,11 +34,11 @@ public class GoogleUserInfoEntity extends BaseEntity {
@JsonProperty("picture")
public String profileImageUrl;

public Member toGoogleDomain(Member member) {
public Member toGoogleDomain(Member member, String basicProfileImageUrl) {
return Member.builder()
.email(email)
.nickname(member.getNickname())
.profileImage(BASIC_PROFILE_IMAGE_URL)
.profileImage(basicProfileImageUrl)
.snsProvider(SnsProvider.GOOGLE)
.idToken(idToken)
.role(MemberRole.ROLE_USER)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,21 @@
import org.depromeet.spot.domain.member.enums.MemberRole;
import org.depromeet.spot.domain.member.enums.SnsProvider;
import org.depromeet.spot.infrastructure.jpa.common.entity.BaseEntity;
import org.springframework.beans.factory.annotation.Value;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Getter
@NoArgsConstructor // 역직렬화를 위한 기본 생성자
@JsonIgnoreProperties(ignoreUnknown = true)
public class KakaoUserInfoEntity extends BaseEntity {

@Value("${aws.s3.basicProfileImageUrl}")
private String BASIC_PROFILE_IMAGE_URL;

// 서비스에 연결 완료된 시각. UTC
@JsonProperty("connected_at")
public Date connectedAt;
Expand Down Expand Up @@ -98,13 +96,13 @@ public class Profile {
}
}

public Member toKakaoDomain(Member member) {
public Member toKakaoDomain(Member member, String basicProfileImageUrl) {
return Member.builder()
.email(kakaoAccount.email)
.name(kakaoAccount.name)
.nickname(member.getNickname())
.phoneNumber(kakaoAccount.phoneNumber)
.profileImage(BASIC_PROFILE_IMAGE_URL)
.profileImage(basicProfileImageUrl)
.snsProvider(SnsProvider.KAKAO)
.idToken(getId().toString())
.role(MemberRole.ROLE_USER)
Expand Down

0 comments on commit aed3851

Please sign in to comment.