Skip to content

Commit 3761049

Browse files
authored
πŸ”€ :: (#215) οΏ½Github OAuth μ—°λ™λλŠ”μ§€ νŒλ³„ μ—¬λΆ€ API μΆ”κ°€
πŸ”€ :: (#215) οΏ½Github OAuth μ—°λ™λλŠ”μ§€ νŒλ³„ μ—¬λΆ€ API μΆ”κ°€
2 parents a235d47 + 0a876f8 commit 3761049

File tree

7 files changed

+33
-0
lines changed

7 files changed

+33
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.xquare.v1servicegit.git.dto.response
2+
3+
data class IsConnectedGithubOauthResponse(
4+
val isConnected: Boolean,
5+
)

β€Žgit-application/src/main/kotlin/com/xquare/v1servicegit/git/port/QueryGitPort.kt

+1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ interface QueryGitPort {
99
suspend fun getGitByUserId(userId: UUID): Git?
1010
suspend fun getGitByUsername(username: String): Git?
1111
suspend fun getContributionCount(username: String): Int
12+
suspend fun isExistGitUserByUserId(userId: UUID): Boolean
1213
}

β€Žgit-application/src/main/kotlin/com/xquare/v1servicegit/git/usecase/GitUseCase.kt

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.xquare.v1servicegit.common.annotations.UseCase
44
import com.xquare.v1servicegit.git.Git
55
import com.xquare.v1servicegit.git.dto.request.FindUserInfoRequest
66
import com.xquare.v1servicegit.git.dto.response.FindAllUserResponse
7+
import com.xquare.v1servicegit.git.dto.response.IsConnectedGithubOauthResponse
78
import com.xquare.v1servicegit.git.dto.response.toUserElement
89
import com.xquare.v1servicegit.git.exceptions.GitExceptions
910
import com.xquare.v1servicegit.git.port.CommandGitPort
@@ -71,4 +72,10 @@ class GitUseCase(
7172
)
7273
}
7374
}
75+
76+
suspend fun isConnectedGithubOauthByUserId(userId: UUID): IsConnectedGithubOauthResponse =
77+
when (queryGitPort.isExistGitUserByUserId(userId)) {
78+
true -> IsConnectedGithubOauthResponse(true)
79+
false -> IsConnectedGithubOauthResponse(false)
80+
}
7481
}

β€Žgit-infrastructure/src/main/kotlin/com/xquare/v1servicegit/common/config/SecurityConfiguration.kt

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class SecurityConfiguration {
2727
.pathMatchers(HttpMethod.POST, "/gits").permitAll()
2828
.pathMatchers(HttpMethod.GET, "/gits").permitAll()
2929
.pathMatchers(HttpMethod.GET, "/gits/all").permitAll()
30+
.pathMatchers(HttpMethod.GET, "/gits/exist").permitAll()
3031
.pathMatchers(HttpMethod.PATCH, "/gits").permitAll()
3132
.anyExchange().authenticated()
3233
.and()

β€Žgit-infrastructure/src/main/kotlin/com/xquare/v1servicegit/git/GitPersistenceAdapter.kt

+12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.linecorp.kotlinjdsl.query.HibernateMutinyReactiveQueryFactory
55
import com.linecorp.kotlinjdsl.query.singleQueryOrNull
66
import com.linecorp.kotlinjdsl.querydsl.expression.col
77
import com.linecorp.kotlinjdsl.selectQuery
8+
import com.linecorp.kotlinjdsl.singleQueryOrNull
89
import com.xquare.v1servicegit.git.port.GitPort
910
import io.smallrye.mutiny.coroutines.awaitSuspending
1011
import kotlinx.coroutines.CoroutineScope
@@ -134,4 +135,15 @@ class GitPersistenceAdapter(
134135
}
135136
}.awaitAll().associate { (userId, contribution) -> userId to contribution }
136137
}
138+
139+
override suspend fun isExistGitUserByUserId(userId: UUID): Boolean =
140+
reactiveQueryFactory.withFactory { _, reactiveQueryFactory ->
141+
reactiveQueryFactory.singleQueryOrNull<UUID> {
142+
select(col(GitEntity::userId))
143+
from(entity(GitEntity::class))
144+
where(
145+
col(GitEntity::userId).equal(userId),
146+
)
147+
} != null
148+
}
137149
}

β€Žgit-infrastructure/src/main/kotlin/com/xquare/v1servicegit/git/router/GitHandler.kt

+6
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,10 @@ class GitHandler(
3737
gitUseCase.updateGitInfo()
3838
return ServerResponse.noContent().buildAndAwait()
3939
}
40+
41+
suspend fun isConnectedGithubOauthByUserId(serverRequest: ServerRequest): ServerResponse {
42+
val currentUserId = requestHeaderAspect.getCurrentUserId(serverRequest)
43+
val isConnectedGithubOauth = gitUseCase.isConnectedGithubOauthByUserId(currentUserId)
44+
return ServerResponse.ok().bodyValueAndAwait(isConnectedGithubOauth)
45+
}
4046
}

β€Žgit-infrastructure/src/main/kotlin/com/xquare/v1servicegit/git/router/GitRouter.kt

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class GitRouter {
1414
POST("", gitHandler::saveGithubUserInfo)
1515
GET("/all", gitHandler::getAllGithubInfo)
1616
GET("", gitHandler::getMyGithubInfo)
17+
GET("/exist", gitHandler::isConnectedGithubOauthByUserId)
1718
PATCH("", gitHandler::updateContributions)
1819
}
1920
}

0 commit comments

Comments
Β (0)