-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
feb4b82
commit 8f8520c
Showing
11 changed files
with
156 additions
and
25 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
src/main/kotlin/com/hero/alignlab/client/kakao/KakaoInfoService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.hero.alignlab.client.kakao | ||
|
||
import com.hero.alignlab.client.kakao.client.KaKaoInfoClient | ||
import com.hero.alignlab.client.kakao.model.response.KakaoOAuthUserInfoResponse | ||
import com.hero.alignlab.common.extension.resolveCancellation | ||
import io.github.oshai.kotlinlogging.KotlinLogging | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class KakaoInfoService( | ||
private val kaKaoInfoClient: KaKaoInfoClient, | ||
) { | ||
private val logger = KotlinLogging.logger { } | ||
|
||
suspend fun getUserInfo(accessToken: String): KakaoOAuthUserInfoResponse { | ||
return runCatching { | ||
kaKaoInfoClient.getUserInfo(accessToken) | ||
}.onFailure { e -> | ||
logger.resolveCancellation("getUserInfo", e) | ||
}.getOrThrow() | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/com/hero/alignlab/client/kakao/client/KaKaoInfoClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.hero.alignlab.client.kakao.client | ||
|
||
import com.hero.alignlab.client.kakao.model.response.KakaoOAuthUserInfoResponse | ||
|
||
interface KaKaoInfoClient { | ||
suspend fun getUserInfo(accessToken: String): KakaoOAuthUserInfoResponse | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/kotlin/com/hero/alignlab/client/kakao/client/SuspendableKakaoInfoClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.hero.alignlab.client.kakao.client | ||
|
||
import com.hero.alignlab.client.kakao.SuspendableClient | ||
import com.hero.alignlab.client.kakao.model.response.KakaoOAuthUserInfoResponse | ||
import org.springframework.web.reactive.function.client.WebClient | ||
|
||
class SuspendableKakaoInfoClient(client: WebClient) : KaKaoInfoClient, SuspendableClient(client) { | ||
override suspend fun getUserInfo(accessToken: String): KakaoOAuthUserInfoResponse { | ||
return client.get() | ||
.uri("/v2/user/me") | ||
.header("Authorization", "Bearer $accessToken") | ||
.request() | ||
} | ||
} |
6 changes: 1 addition & 5 deletions
6
src/main/kotlin/com/hero/alignlab/client/kakao/client/SuspendableKakaoOAuthClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/kotlin/com/hero/alignlab/client/kakao/config/KakaoInfoClientConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.hero.alignlab.client.kakao.config | ||
|
||
import com.hero.alignlab.client.WebClientFactory | ||
import com.hero.alignlab.client.kakao.client.KaKaoInfoClient | ||
import com.hero.alignlab.client.kakao.client.KaKaoOAuthClient | ||
import com.hero.alignlab.client.kakao.client.SuspendableKakaoInfoClient | ||
import io.github.oshai.kotlinlogging.KotlinLogging | ||
import jakarta.validation.Valid | ||
import jakarta.validation.constraints.NotBlank | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty | ||
import org.springframework.boot.context.properties.ConfigurationProperties | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.validation.annotation.Validated | ||
|
||
@Validated | ||
@Configuration | ||
class KakaoInfoClientConfig { | ||
private val logger = KotlinLogging.logger { } | ||
|
||
@Bean | ||
@ConditionalOnProperty(prefix = "client.kakao-info", name = ["url"]) | ||
@ConfigurationProperties(prefix = "client.kakao-info") | ||
fun kakaoInfoConfig() = Config() | ||
|
||
@Bean | ||
@ConditionalOnBean(name = ["kakaoInfoConfig"]) | ||
@ConditionalOnMissingBean(KaKaoOAuthClient::class) | ||
fun kakaoInfoClient( | ||
@Valid kakaoInfoConfig: Config | ||
): KaKaoInfoClient { | ||
logger.info { "initialized KaKaoInfoClient. $kakaoInfoConfig" } | ||
|
||
val webclient = WebClientFactory.generate(kakaoInfoConfig.url) | ||
|
||
return SuspendableKakaoInfoClient(webclient) | ||
} | ||
|
||
data class Config( | ||
@field:NotBlank | ||
var url: String = "", | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/kotlin/com/hero/alignlab/client/kakao/model/response/KakaoOAuthUserInfoResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.hero.alignlab.client.kakao.model.response | ||
|
||
import com.fasterxml.jackson.databind.PropertyNamingStrategies | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming | ||
import java.time.LocalDateTime | ||
|
||
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy::class) | ||
data class KakaoOAuthUserInfoResponse( | ||
val id: String, | ||
val hasSignedUp: Boolean?, | ||
val connectedAt: LocalDateTime?, | ||
val synchedAt: LocalDateTime?, | ||
val kakaoAccount: KakaoAccount?, | ||
) { | ||
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy::class) | ||
data class KakaoAccount( | ||
val profileNeedsAgreement: Boolean?, | ||
val profile: Profile?, | ||
val nameNeedsAgreement: Boolean?, | ||
val name: String?, | ||
val emailNeedsAgreement: Boolean?, | ||
val isEmailValid: Boolean?, | ||
val isEmailVerified: Boolean?, | ||
val email: String?, | ||
val ageRangeNeedsAgreement: Boolean?, | ||
val ageRange: String?, | ||
val birthyearNeedsAgreement: Boolean?, | ||
val birthyear: String?, | ||
val birthdayNeedsAgreement: Boolean?, | ||
val birthday: String?, | ||
val birthdayType: String?, | ||
val genderNeedsAgreement: Boolean?, | ||
val gender: String?, | ||
val phoneNumberNeedsAgreement: Boolean?, | ||
val phoneNumber: String?, | ||
val ciNeedsAgreement: Boolean?, | ||
val ci: String?, | ||
val ciAuthenticatedAt: LocalDateTime?, | ||
) | ||
|
||
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy::class) | ||
data class Profile( | ||
val nickname: String?, | ||
val thumbnailImageUrl: String?, | ||
val profileImageUrl: String?, | ||
val isDefaultImage: Boolean?, | ||
val isDefaultNickname: Boolean?, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters