Skip to content

Commit

Permalink
Merge pull request #58 from depromeet/feature/#16-profile
Browse files Browse the repository at this point in the history
유저 프로필 이미지 추가
  • Loading branch information
ManHyuk authored Dec 21, 2023
2 parents 7c6f550 + 3502fee commit 4c2420a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ data class UserResponse(
val username: String?,
val nickname: String?,
val birth: LocalDate?,
val image: String,
) {
companion object {
fun of(user: User): UserResponse {
Expand All @@ -18,6 +19,7 @@ data class UserResponse(
username = user.userName,
nickname = user.nickname,
birth = user.birth,
image = user.image,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class OAuth2UserService(
OAuthProvider.GOOGLE -> {
val email = oAuth2User.attributes["email"]?.toString() ?: throw RuntimeException("이메일이없음")
val name = oAuth2User.attributes["name"]
val user = upsert(email, OAuthProvider.GOOGLE)
val image = oAuth2User.attributes["picture"]?.toString() ?: ""
val user = upsert(email, image, OAuthProvider.GOOGLE)
CurrentUser(
id = user.id!!,
email = email,
Expand All @@ -35,7 +36,8 @@ class OAuth2UserService(
OAuthProvider.NAVER -> {
val userInfo = oAuth2User.attributes[usernameAttributeName] as Map<String, String>
val email = userInfo["email"] ?: throw RuntimeException("이메일없음")
val user = upsert(email, OAuthProvider.NAVER)
val image = ""
val user = upsert(email, image, OAuthProvider.NAVER)
CurrentUser(
id = user.id!!,
email = email,
Expand All @@ -45,11 +47,12 @@ class OAuth2UserService(
}
}

private fun upsert(email: String, oAuthProvider: OAuthProvider): User {
private fun upsert(email: String, image: String, oAuthProvider: OAuthProvider): User {
return userRepository.findByEmail(email)
?: return userRepository.save(
User(
email = email,
image = image,
provider = oAuthProvider,
authority = Authority.ROLE_USER,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ class GoalReadServiceTest {

companion object {
val USER_FIXTURE = User(
"[email protected]",
"binaryHoHo",
"binaryHoHoHo",
LocalDate.MIN,
OAuthProvider.NAVER,
Authority.ROLE_USER,
email = "[email protected]",
userName = "binaryHoHo",
nickname = "binaryHoHoHo",
birth = LocalDate.MIN,
image = "",
provider = OAuthProvider.NAVER,
authority = Authority.ROLE_USER,
)

val STICKER_FIXTURE = Sticker("sticker", "image yeah")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ class TaskServiceTest {
email = "[email protected]",
userName = "binaryHoHo",
nickname = "binaryHoHoHo",
LocalDate.MIN,
OAuthProvider.NAVER,
Authority.ROLE_USER,
image = "",
birth = LocalDate.MIN,
provider = OAuthProvider.NAVER,
authority = Authority.ROLE_USER,
)

val STICKER_FIXTURE = Sticker("sticker", "image yeah")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class User(
@Column
val birth: LocalDate? = null,

@Column
val image: String,

@Column
@Enumerated(EnumType.STRING)
val provider: OAuthProvider,
Expand All @@ -45,6 +48,7 @@ class User(
email = email,
nickname = nickname,
birth = birth,
image = image,
provider = provider,
authority = authority,
id = id,
Expand Down

0 comments on commit 4c2420a

Please sign in to comment.