Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev #32

Merged
merged 7 commits into from
Apr 24, 2024
Merged

dev #32

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ kotlin {
implementation(project(":feature:follower"))
implementation(project(":feature:favourite"))
implementation(project(":feature:settings"))
implementation(project(":feature:match"))
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion composeApp/src/commonMain/kotlin/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.stslex.feature.favourite.di.featureFavouriteModule
import com.stslex.feature.film.di.featureFilmModule
import com.stslex.feature.film_feed.di.featureFeedModule
import com.stslex.feature.follower.di.featureFollowerModule
import com.stslex.feature.match.di.featureMatchModule
import com.stslex.feature.match_feed.di.featureMatchFeedModule
import com.stslex.feature.profile.di.featureProfileModule
import com.stslex.feature.settings.di.featureSettingsModule
Expand Down Expand Up @@ -47,7 +48,8 @@ private fun KoinApplication.setupCommonModules() {
featureAuthModule,
featureFollowerModule,
featureFavouriteModule,
featureSettingsModule
featureSettingsModule,
featureMatchModule
)
)
}
2 changes: 1 addition & 1 deletion composeApp/src/commonMain/kotlin/InitialApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fun InitialApp(
modifier = modifier
.fillMaxSize()
.background(MaterialTheme.colorScheme.background)
) { paddingValues ->
) { _ ->
Box(
modifier = Modifier.fillMaxSize()
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ enum class BottomNavigationTabs(
val tab: Tab
) {
FILM_FEED(FeedTab),
MATCH_FEED(MatchFeedTab),
MATCH_FEED(MatchTab),
PROFILE(ProfileTab),
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main_screen.bottom_nav_bar

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.List
import androidx.compose.material.icons.automirrored.filled.List
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.vector.rememberVectorPainter
Expand All @@ -17,7 +17,7 @@ object FeedTab : Tab {
@Composable
get() {
val title = "feed"
val icon = rememberVectorPainter(Icons.Default.List)
val icon = rememberVectorPainter(Icons.AutoMirrored.Filled.List)

return remember {
TabOptions(
Expand All @@ -30,7 +30,7 @@ object FeedTab : Tab {

@Composable
override fun Content() {
Navigator(FeedScreen){
Navigator(FeedScreen) {
SlideTransition(it)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import androidx.compose.ui.graphics.vector.rememberVectorPainter
import cafe.adriel.voyager.navigator.Navigator
import cafe.adriel.voyager.navigator.tab.Tab
import cafe.adriel.voyager.navigator.tab.TabOptions
import com.stslex.feature.match_feed.ui.MatchFeedScreen
import com.stslex.core.ui.navigation.args.MatchScreenArgs
import com.stslex.feature.match.ui.MatchScreen

object MatchFeedTab : Tab {
object MatchTab : Tab {

override val options: TabOptions
@Composable
Expand All @@ -29,6 +30,6 @@ object MatchFeedTab : Tab {

@Composable
override fun Content() {
Navigator(MatchFeedScreen)
Navigator(MatchScreen(MatchScreenArgs.Self))
}
}
13 changes: 8 additions & 5 deletions composeApp/src/commonMain/kotlin/navigator/AppNavigatorImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.stslex.feature.favourite.FavouriteScreen
import com.stslex.feature.film.ui.FilmScreen
import com.stslex.feature.follower.navigation.FollowerScreenArgs
import com.stslex.feature.follower.ui.FollowerScreen
import com.stslex.feature.match.ui.MatchScreen
import com.stslex.feature.match_feed.ui.MatchFeedScreen
import com.stslex.feature.settings.ui.SettingsScreen
import main_screen.MainScreen
Expand Down Expand Up @@ -35,15 +36,17 @@ class AppNavigatorImpl : AppNavigator {
screen: AppScreen
) {
when (screen) {
AppScreen.Back -> navigator.pop()
AppScreen.Auth -> navigator.replaceAll(AuthScreen)
AppScreen.Main -> navigator.replaceAll(MainScreen)
is AppScreen.Back -> navigator.pop()
is AppScreen.Auth -> navigator.replaceAll(AuthScreen)
is AppScreen.Main -> navigator.replaceAll(MainScreen)
is AppScreen.Film -> navigator.push(FilmScreen(screen.id))
AppScreen.MatchFeed -> navigator.push(MatchFeedScreen)
is AppScreen.MatchFeed -> navigator.push(MatchFeedScreen)
is AppScreen.Favourite -> navigator.push(FavouriteScreen(uuid = screen.uuid))
is AppScreen.Followers -> navToFollowers(screen.uuid)
is AppScreen.Following -> navToFollowing(screen.uuid)
AppScreen.Settings -> navigator.push(SettingsScreen)
is AppScreen.Settings -> navigator.push(SettingsScreen)
is AppScreen.MatchDetails -> TODO()
is AppScreen.Match -> navigator.push(MatchScreen(args = screen.args))
}
}

Expand Down
4 changes: 2 additions & 2 deletions core/core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import org.jetbrains.compose.ExperimentalComposeLibrary

plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidLibrary)
alias(libs.plugins.jetbrainsCompose)
alias(libs.plugins.kotlinCocoapods)
alias(libs.plugins.kotlinSerialization)
}

kotlin {
Expand Down Expand Up @@ -41,6 +40,7 @@ kotlin {
api(libs.koin.compose)
api(libs.kotlinx.collections.immutable)
api(libs.coroutines.core)
implementation(libs.kotlinx.serialization.json)
}
androidMain.dependencies {
api(libs.coroutines.android)
Expand Down
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()
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
}
}
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
}
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)
},
)
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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ class ServerApiClientImpl(
request(client.authClient)
}
}
}
}
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
}
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"
}
}
Loading
Loading