-
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.
Merge pull request #32 from stslex/dev
dev
- Loading branch information
Showing
84 changed files
with
1,687 additions
and
92 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
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
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
11 changes: 10 additions & 1 deletion
11
core/core/src/commonMain/kotlin/com/stslex/core/core/CommonUtils.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,9 +1,18 @@ | ||
package com.stslex.core.core | ||
|
||
import kotlinx.coroutines.CoroutineExceptionHandler | ||
import kotlinx.coroutines.async | ||
import kotlinx.coroutines.awaitAll | ||
import kotlinx.coroutines.coroutineScope | ||
|
||
val coroutineExceptionHandler = CoroutineExceptionHandler { _, throwable -> | ||
Logger.exception(throwable) | ||
} | ||
|
||
expect fun randomUuid(): String | ||
expect fun randomUuid(): String | ||
|
||
suspend fun <T, R> List<T>.asyncMap( | ||
transform: suspend (T) -> R | ||
): List<R> = coroutineScope { | ||
map { item -> async { transform(item) } } | ||
}.awaitAll() |
15 changes: 15 additions & 0 deletions
15
core/core/src/commonMain/kotlin/com/stslex/core/core/paging/PagingCoreData.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,15 @@ | ||
package com.stslex.core.core.paging | ||
|
||
interface PagingCoreData<out T : PagingCoreItem> { | ||
val page: Int | ||
val pageSize: Int | ||
val total: Int | ||
val hasMore: Boolean | ||
val result: List<T> | ||
|
||
companion object { | ||
|
||
const val DEFAULT_PAGE_SIZE = 15 | ||
const val DEFAULT_PAGE = 0 | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
core/core/src/commonMain/kotlin/com/stslex/core/core/paging/PagingCoreItem.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,5 @@ | ||
package com.stslex.core.core.paging | ||
|
||
interface PagingCoreItem { | ||
val uuid: String | ||
} |
31 changes: 31 additions & 0 deletions
31
core/core/src/commonMain/kotlin/com/stslex/core/core/paging/PagingResponse.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,31 @@ | ||
package com.stslex.core.core.paging | ||
|
||
import com.stslex.core.core.asyncMap | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class PagingResponse<out T : PagingCoreItem>( | ||
@SerialName("page") | ||
override val page: Int, | ||
@SerialName("page_size") | ||
override val pageSize: Int, | ||
@SerialName("total") | ||
override val total: Int, | ||
@SerialName("has_more") | ||
override val hasMore: Boolean, | ||
@SerialName("result") | ||
override val result: List<T>, | ||
) : PagingCoreData<T> | ||
|
||
suspend fun <T : PagingCoreItem, R : PagingCoreItem> PagingResponse<T>.pagingMap( | ||
transform: suspend (T) -> R, | ||
): PagingResponse<R> = PagingResponse( | ||
page = page, | ||
pageSize = pageSize, | ||
total = total, | ||
hasMore = hasMore, | ||
result = result.asyncMap { | ||
transform(it) | ||
}, | ||
) |
42 changes: 42 additions & 0 deletions
42
core/network/src/commonMain/kotlin/com/stslex/core/network/api/base/NetworkClient.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,8 +1,50 @@ | ||
package com.stslex.core.network.api.base | ||
|
||
import com.stslex.core.network.api.base.NetworkClient.Companion.PARAMETER_PAGE | ||
import com.stslex.core.network.api.base.NetworkClient.Companion.PARAMETER_PAGE_SIZE | ||
import com.stslex.core.network.api.base.NetworkClient.Companion.PARAMETER_QUERY | ||
import com.stslex.core.network.api.base.NetworkClient.Companion.PARAMETER_UUID | ||
import com.stslex.core.network.model.PagingRequest | ||
import io.ktor.client.HttpClient | ||
import io.ktor.client.call.body | ||
import io.ktor.client.request.HttpRequestBuilder | ||
import io.ktor.client.request.get | ||
import io.ktor.client.request.parameter | ||
import io.ktor.client.request.post | ||
|
||
interface NetworkClient { | ||
|
||
suspend fun <T> request(request: suspend HttpClient.() -> T): T | ||
|
||
companion object { | ||
internal const val PARAMETER_QUERY = "query" | ||
internal const val PARAMETER_PAGE = "page" | ||
internal const val PARAMETER_PAGE_SIZE = "page_size" | ||
internal const val PARAMETER_UUID = "uuid" | ||
} | ||
} | ||
|
||
internal suspend inline fun <reified T> NetworkClient.get( | ||
urlString: String = "", | ||
crossinline builder: suspend HttpRequestBuilder.() -> Unit | ||
): T = request { | ||
get(urlString = urlString) { | ||
builder() | ||
}.body() | ||
} | ||
|
||
internal suspend inline fun <reified T> NetworkClient.post( | ||
urlString: String = "", | ||
crossinline builder: suspend HttpRequestBuilder.() -> Unit | ||
): T = request { | ||
post(urlString = urlString) { | ||
builder() | ||
}.body() | ||
} | ||
|
||
internal fun HttpRequestBuilder.requestPaging(request: PagingRequest) { | ||
parameter(PARAMETER_UUID, request.uuid) | ||
parameter(PARAMETER_QUERY, request.query) | ||
parameter(PARAMETER_PAGE, request.page) | ||
parameter(PARAMETER_PAGE_SIZE, request.pageSize) | ||
} |
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 |
---|---|---|
|
@@ -20,4 +20,4 @@ class ServerApiClientImpl( | |
request(client.authClient) | ||
} | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...network/src/commonMain/kotlin/com/stslex/core/network/clients/match/client/MatchClient.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,16 @@ | ||
package com.stslex.core.network.clients.match.client | ||
|
||
import com.stslex.core.core.paging.PagingResponse | ||
import com.stslex.core.network.clients.match.model.request.MatchCreateRequest | ||
import com.stslex.core.network.clients.match.model.response.MatchDetailResponse | ||
import com.stslex.core.network.clients.match.model.response.MatchResponse | ||
import com.stslex.core.network.model.PagingRequest | ||
|
||
interface MatchClient { | ||
|
||
suspend fun getMatches(request: PagingRequest): PagingResponse<MatchResponse> | ||
|
||
suspend fun getMatch(matchUuid: String): MatchDetailResponse | ||
|
||
suspend fun createMatch(request: MatchCreateRequest): MatchDetailResponse | ||
} |
42 changes: 42 additions & 0 deletions
42
...ork/src/commonMain/kotlin/com/stslex/core/network/clients/match/client/MatchClientImpl.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,42 @@ | ||
package com.stslex.core.network.clients.match.client | ||
|
||
import com.stslex.core.core.paging.PagingResponse | ||
import com.stslex.core.network.api.base.get | ||
import com.stslex.core.network.api.base.post | ||
import com.stslex.core.network.api.base.requestPaging | ||
import com.stslex.core.network.api.server.client.ServerApiClient | ||
import com.stslex.core.network.clients.match.model.request.MatchCreateRequest | ||
import com.stslex.core.network.clients.match.model.response.MatchDetailResponse | ||
import com.stslex.core.network.clients.match.model.response.MatchResponse | ||
import com.stslex.core.network.model.PagingRequest | ||
import io.ktor.client.request.parameter | ||
import io.ktor.client.request.setBody | ||
|
||
class MatchClientImpl( | ||
private val client: ServerApiClient | ||
) : MatchClient { | ||
|
||
override suspend fun getMatches( | ||
request: PagingRequest | ||
): PagingResponse<MatchResponse> = client.get("$HOST/list") { | ||
requestPaging(request) | ||
} | ||
|
||
override suspend fun getMatch( | ||
matchUuid: String | ||
): MatchDetailResponse = client.get("$HOST/detail") { | ||
parameter(PARAMETER_MATCH_UUID, matchUuid) | ||
} | ||
|
||
override suspend fun createMatch( | ||
request: MatchCreateRequest | ||
): MatchDetailResponse = client.post("$HOST/create") { | ||
setBody(request) | ||
} | ||
|
||
companion object { | ||
|
||
private const val HOST = "match" | ||
private const val PARAMETER_MATCH_UUID = "match_uuid" | ||
} | ||
} |
Oops, something went wrong.