-
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.
* feat: member name profile image 추가 * test: 빌드 실패 해결
- Loading branch information
1 parent
b6913cb
commit 6239486
Showing
13 changed files
with
160 additions
and
6 deletions.
There are no files selected for viewing
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
6 changes: 6 additions & 0 deletions
6
src/main/kotlin/com/poseplz/server/application/auth/ProviderUserNameService.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,6 @@ | ||
package com.poseplz.server.application.auth | ||
|
||
interface ProviderUserNameService { | ||
fun getProviderUserName(loginRequestVo: LoginRequestVo): String? | ||
fun supports(loginRequestVo: LoginRequestVo): Boolean | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/kotlin/com/poseplz/server/application/auth/ProviderUserProfileImageService.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,6 @@ | ||
package com.poseplz.server.application.auth | ||
|
||
interface ProviderUserProfileImageService { | ||
fun getProviderUserProfileImage(loginRequestVo: LoginRequestVo): String? | ||
fun supports(loginRequestVo: LoginRequestVo): 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
32 changes: 32 additions & 0 deletions
32
src/main/kotlin/com/poseplz/server/infrastructure/kakao/KakaoAdminSdkClient.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,32 @@ | ||
package com.poseplz.server.infrastructure.kakao | ||
|
||
import org.springframework.beans.factory.annotation.Qualifier | ||
import org.springframework.stereotype.Component | ||
import org.springframework.web.client.RestClientException | ||
import org.springframework.web.client.RestTemplate | ||
import org.springframework.web.util.UriComponentsBuilder | ||
|
||
@Component | ||
class KakaoAdminApiClient( | ||
@Qualifier("kakaoAdminRestTemplate") | ||
private val kakaoAdminRestTemplate: RestTemplate, | ||
) { | ||
fun getUserInfo( | ||
kakaoUserId: String, | ||
): KakaoUserMeResponse { | ||
|
||
return try { | ||
val responseEntity = kakaoAdminRestTemplate.getForEntity( | ||
UriComponentsBuilder.fromHttpUrl("https://kapi.kakao.com/v1/user/me") | ||
.queryParam("target_id_type", "user_id") | ||
.queryParam("target_id", kakaoUserId) | ||
.build() | ||
.toUri(), | ||
KakaoUserMeResponse::class.java, | ||
) | ||
responseEntity.body!! | ||
} catch (e: RestClientException) { | ||
throw KakaoApiFailedException("카카오 사용자 정보 가져오기 API 호출에 실패했습니다.", e) | ||
} | ||
} | ||
} |
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
23 changes: 23 additions & 0 deletions
23
src/main/kotlin/com/poseplz/server/infrastructure/kakao/KakaoConfig.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 |
---|---|---|
@@ -1,18 +1,41 @@ | ||
package com.poseplz.server.infrastructure.kakao | ||
|
||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.boot.web.client.RestTemplateBuilder | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.http.client.ClientHttpRequestInterceptor | ||
import org.springframework.web.client.RestTemplate | ||
import java.time.Duration | ||
|
||
@Configuration | ||
class KakaoConfig { | ||
@Value("\${poseplz.kakao.api.admin-key}") | ||
lateinit var kakaoAdminSdkKey: String | ||
|
||
@Bean("kakaoRestTemplate") | ||
fun kakaoRestTemplate(): RestTemplate { | ||
return RestTemplateBuilder() | ||
.setConnectTimeout(Duration.ofSeconds(1)) | ||
.setReadTimeout(Duration.ofSeconds(3)) | ||
.build() | ||
} | ||
|
||
@Bean("kakaoAdminRestTemplate") | ||
fun kakaoAdminRestTemplate(): RestTemplate { | ||
return RestTemplateBuilder() | ||
.setConnectTimeout(Duration.ofSeconds(1)) | ||
.setReadTimeout(Duration.ofSeconds(3)) | ||
.additionalInterceptors(kakaoAdminApiHeaderInterceptor()) | ||
.build() | ||
} | ||
|
||
@Bean | ||
fun kakaoAdminApiHeaderInterceptor(): ClientHttpRequestInterceptor { | ||
return ClientHttpRequestInterceptor { request, body, execution -> | ||
request.headers.set("Authorization", "KakaoAK ${kakaoAdminSdkKey}") | ||
request.headers.set("Content-Type", "application/x-www-form-urlencoded;charset=utf-8") | ||
execution.execute(request, body) | ||
} | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
src/main/kotlin/com/poseplz/server/infrastructure/kakao/KakaoUserMeResponse.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,25 @@ | ||
package com.poseplz.server.infrastructure.kakao | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty | ||
import java.time.ZonedDateTime | ||
|
||
data class KakaoUserMeResponse ( | ||
val id: Long, | ||
@JsonProperty("connected_at") | ||
val connectedAt: ZonedDateTime, | ||
@JsonProperty("kakao_account") | ||
val kakaoAccount: KakaoAccount? = null, | ||
) | ||
|
||
data class KakaoAccount ( | ||
val profile: KakaoProfile, | ||
) | ||
|
||
data class KakaoProfile ( | ||
@JsonProperty("nickname") | ||
val nickName: String?, | ||
@JsonProperty("thumbnail_image_url") | ||
val thumbnailImageUrl: String?, | ||
@JsonProperty("profile_image_url") | ||
val profileImageUrl: String?, | ||
) |
21 changes: 21 additions & 0 deletions
21
src/main/kotlin/com/poseplz/server/infrastructure/kakao/KakaoUserNameService.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,21 @@ | ||
package com.poseplz.server.infrastructure.kakao | ||
|
||
import com.poseplz.server.application.auth.LoginRequestVo | ||
import com.poseplz.server.application.auth.ProviderUserNameService | ||
import com.poseplz.server.domain.member.ProviderType | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class KakaoUserNameService( | ||
private val kakaoApiClient: KakaoApiClient, | ||
) : ProviderUserNameService { | ||
override fun getProviderUserName(loginRequestVo: LoginRequestVo): String? { | ||
return kakaoApiClient.getKakaoUserInfo(loginRequestVo.providerUserCredential!!) | ||
.kakaoAccount | ||
?.profile | ||
?.nickName | ||
} | ||
|
||
override fun supports(loginRequestVo: LoginRequestVo) = | ||
loginRequestVo.providerType == ProviderType.KAKAO | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/kotlin/com/poseplz/server/infrastructure/kakao/KakaoUserProfileImageService.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,21 @@ | ||
package com.poseplz.server.infrastructure.kakao | ||
|
||
import com.poseplz.server.application.auth.LoginRequestVo | ||
import com.poseplz.server.application.auth.ProviderUserProfileImageService | ||
import com.poseplz.server.domain.member.ProviderType | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class KakaoUserProfileImageService( | ||
private val kakaoApiClient: KakaoApiClient, | ||
) : ProviderUserProfileImageService { | ||
override fun getProviderUserProfileImage(loginRequestVo: LoginRequestVo): String? { | ||
return kakaoApiClient.getKakaoUserInfo(loginRequestVo.providerUserCredential!!) | ||
.kakaoAccount | ||
?.profile | ||
?.profileImageUrl | ||
} | ||
|
||
override fun supports(loginRequestVo: LoginRequestVo) = | ||
loginRequestVo.providerType == ProviderType.KAKAO | ||
} |
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