Skip to content

Commit

Permalink
Merge pull request #48 from stslex/dev
Browse files Browse the repository at this point in the history
refactor modules
  • Loading branch information
stslex authored Dec 1, 2024
2 parents 51dc9aa + e9d3d2b commit 57a6851
Show file tree
Hide file tree
Showing 242 changed files with 811 additions and 744 deletions.
5 changes: 3 additions & 2 deletions commonApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ kotlin {
sourceSets.apply {
commonMain.dependencies {
implementation(project(":core:core"))
implementation(project(":core:network"))
implementation(project(":core:network:client"))
implementation(project(":core:network:api"))
implementation(project(":core:database"))
implementation(project(":core:ui"))
implementation(project(":core:ui:kit"))
implementation(project(":core:navigation"))

implementation(project(":feature:film_feed"))
Expand Down
2 changes: 1 addition & 1 deletion commonApp/src/commonMain/kotlin/com/stslex/wizard/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.stslex.wizard

import androidx.compose.runtime.Composable
import com.stslex.wizard.config.KoinApp
import com.stslex.wizard.core.ui.theme.AppTheme
import com.stslex.wizard.core.ui.kit.theme.AppTheme
import org.koin.core.KoinApplication

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import com.stslex.wizard.bottom_bar.BottomAppBarResource.Companion.getByRoute
import com.stslex.wizard.bottom_bar.MainBottomAppBar
import com.stslex.wizard.core.core.Logger
import com.stslex.wizard.core.navigation.Screen
import com.stslex.wizard.core.network.utils.token.AuthController
import com.stslex.wizard.core.network.api.utils.token.AuthController
import com.stslex.wizard.host.AppNavigationHost
import org.koin.compose.getKoin

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import com.stslex.wizard.core.core.ModuleCore
import com.stslex.wizard.core.core.modules
import com.stslex.wizard.core.database.di.ModuleCoreDatabase
import com.stslex.wizard.core.navigation.di.ModuleCoreNavigation
import com.stslex.wizard.core.network.di.ModuleCoreNetwork
import com.stslex.wizard.core.ui.di.ModuleCoreUi
import com.stslex.wizard.core.network.api.di.ModuleCoreNetworkApi
import com.stslex.wizard.core.network.client.di.ModuleCoreNetworkClient
import com.stslex.wizard.core.ui.kit.di.ModuleCoreUi
import com.stslex.wizard.feature.auth.di.ModuleFeatureAuth
import com.stslex.wizard.feature.favourite.di.ModuleFeatureFavourite
import com.stslex.wizard.feature.film.di.ModuleFeatureFilm
Expand All @@ -20,7 +21,8 @@ import com.stslex.wizard.feature.settings.di.ModuleFeatureSettings
fun appModules(navHostController: NavHostController) = listOf(
ModuleCore(),
ModuleCoreUi(),
ModuleCoreNetwork(),
ModuleCoreNetworkClient(),
ModuleCoreNetworkApi(),
ModuleCoreNavigation(navHostController),
ModuleCoreDatabase(),
ModuleFeatureFeed(),
Expand Down
2 changes: 1 addition & 1 deletion core/navigation/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
kotlin {
sourceSets.commonMain.dependencies {
implementation(project(":core:core"))
implementation(project(":core:ui"))
implementation(project(":core:ui:kit"))

api(libs.compose.navigation)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ kotlin {
sourceSets {
commonMain.dependencies {
implementation(project(":core:core"))
implementation(project(":core:network:client"))
implementation(project(":core:database"))
implementation(libs.bundles.ktor)
implementation(libs.slf4j.simple)
Expand Down Expand Up @@ -38,4 +39,4 @@ fun BuildConfigExtension.buildStringField(localProperties: Properties, name: Str

fun Properties.getString(key: String): String {
return getProperty(key) ?: throw IllegalStateException("$key should be initialised")
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package com.stslex.wizard.core.network.api.base
package com.stslex.wizard.core.network.api.api.base

import com.stslex.wizard.core.core.AppDispatcher
import com.stslex.wizard.core.network.api.base.NetworkClientBuilder.setupDefaultRequest
import com.stslex.wizard.core.network.api.base.NetworkClientBuilder.setupLogging
import com.stslex.wizard.core.network.api.base.NetworkClientBuilder.setupNegotiation
import com.stslex.wizard.core.network.api.base.model.DefaultRequest
import com.stslex.wizard.core.network.client.DefaultRequest
import com.stslex.wizard.core.network.client.NetworkClientBuilder.setupDefaultRequest
import io.ktor.client.HttpClient
import io.ktor.client.engine.cio.CIO
import io.ktor.client.plugins.cache.HttpCache
import kotlinx.coroutines.withContext

open class BaseNetworkClient(
private val appDispatcher: AppDispatcher,
client: HttpClient,
defaultRequest: DefaultRequest = DefaultRequest.EMPTY
) : NetworkClient {

Expand All @@ -21,10 +19,8 @@ open class BaseNetworkClient(
request(client)
}

private val client: HttpClient = HttpClient(CIO) {
setupNegotiation()
private val client: HttpClient = client.config {
install(HttpCache)
setupLogging()
expectSuccess = true
setupDefaultRequest(defaultRequest)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.stslex.wizard.core.network.api.base
package com.stslex.wizard.core.network.api.api.base

import com.stslex.wizard.core.network.api.base.NetworkClient.Companion.PARAMETER_PAGE
import com.stslex.wizard.core.network.api.base.NetworkClient.Companion.PARAMETER_PAGE_SIZE
import com.stslex.wizard.core.network.api.base.NetworkClient.Companion.PARAMETER_QUERY
import com.stslex.wizard.core.network.api.base.NetworkClient.Companion.PARAMETER_UUID
import com.stslex.wizard.core.network.model.PagingRequest
import com.stslex.wizard.core.network.api.api.base.NetworkClient.Companion.PARAMETER_PAGE
import com.stslex.wizard.core.network.api.api.base.NetworkClient.Companion.PARAMETER_PAGE_SIZE
import com.stslex.wizard.core.network.api.api.base.NetworkClient.Companion.PARAMETER_QUERY
import com.stslex.wizard.core.network.api.api.base.NetworkClient.Companion.PARAMETER_UUID
import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.request.HttpRequestBuilder
Expand Down Expand Up @@ -42,7 +41,7 @@ internal suspend inline fun <reified T> NetworkClient.post(
}.body()
}

internal fun HttpRequestBuilder.requestPaging(request: PagingRequest) {
internal fun HttpRequestBuilder.requestPaging(request: com.stslex.wizard.core.network.api.model.PagingRequest) {
parameter(PARAMETER_UUID, request.uuid)
parameter(PARAMETER_QUERY, request.query)
parameter(PARAMETER_PAGE, request.page)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.stslex.wizard.core.network.api.api.kinopoisk.api

import com.stslex.wizard.core.network.api.api.base.NetworkClient

interface KinopoiskApiClient : NetworkClient
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.stslex.wizard.core.network.api.api.kinopoisk.api

import Wizard.core.network.api.BuildConfig
import com.stslex.wizard.core.core.AppDispatcher
import com.stslex.wizard.core.network.api.api.base.BaseNetworkClient
import com.stslex.wizard.core.network.client.DefaultRequest
import io.ktor.client.HttpClient

class KinopoiskApiClientImpl(
appDispatcher: AppDispatcher,
client: HttpClient
) : KinopoiskApiClient, BaseNetworkClient(
appDispatcher = appDispatcher,
client = client,
defaultRequest = DEFAULT_REQUEST
) {

companion object {
// TODO parse error
private const val KINOPOISK_HOST_URL = "kinopoiskapiunofficial.tech/api/v2.2"
private const val API_KEY = BuildConfig.KINOPOISK_API_KEY
private const val API_HEADER = "X-API-KEY"
private const val CONTENT_TYPE = "Content-Type"
private const val CONTENT_TYPE_VALUE = "application/json"

private val DEFAULT_REQUEST =
DefaultRequest(
hostUrl = KINOPOISK_HOST_URL,
headers = mapOf(
API_HEADER to API_KEY,
CONTENT_TYPE to CONTENT_TYPE_VALUE
)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.stslex.wizard.core.network.api.api.kinopoisk.model

import com.stslex.wizard.core.network.api.api.kinopoisk.model.network.FilmItemKinopoisk
import com.stslex.wizard.core.network.api.api.kinopoisk.model.network.FilmListKinopoisk
import com.stslex.wizard.core.network.api.api.kinopoisk.model.network.FilmProductionStatusNetwork
import com.stslex.wizard.core.network.api.api.kinopoisk.model.network.FilmTypeNetwork
import com.stslex.wizard.core.network.api.api.kinopoisk.model.network.MovieKinopoisk
import com.stslex.wizard.core.network.api.api.kinopoisk.model.network.TrailerItemKinopoisk
import com.stslex.wizard.core.network.api.api.kinopoisk.model.network.TrailerKinopoisk
import com.stslex.wizard.core.network.api.api.kinopoisk.model.response.FilmItemResponse
import com.stslex.wizard.core.network.api.api.kinopoisk.model.response.FilmListResponse
import com.stslex.wizard.core.network.api.api.kinopoisk.model.response.MovieResponse
import com.stslex.wizard.core.network.api.api.kinopoisk.model.response.TrailerItemResponse
import com.stslex.wizard.core.network.api.api.kinopoisk.model.response.TrailerResponse
import com.stslex.wizard.core.network.api.clients.film.model.TrailerSiteType

fun FilmListResponse.toNetwork(): FilmListKinopoisk = FilmListKinopoisk(
total = total ?: 0,
totalPages = totalPages ?: 0,
items = items?.map { it.toNetwork() }.orEmpty()
)

fun FilmItemResponse.toNetwork(): FilmItemKinopoisk = FilmItemKinopoisk(
kinopoiskId = kinopoiskId,
imdbId = imdbId.orEmpty(),
nameRu = nameRu.orEmpty(),
nameEn = nameEn.orEmpty(),
nameOriginal = nameOriginal.orEmpty(),
countries = countries?.map { it.country }.orEmpty(),
genres = genres?.map { it.genre }.orEmpty(),
ratingKinopoisk = ratingKinopoisk,
ratingImdb = ratingImdb,
year = year,
posterUrl = posterUrl.orEmpty(),
posterUrlPreview = posterUrlPreview.orEmpty(),
type = FilmTypeNetwork.getType(type.orEmpty())
)

fun TrailerResponse.toNetwork(): TrailerKinopoisk = TrailerKinopoisk(
total = total ?: 0,
items = items?.map { it.toNetwork() }.orEmpty()
)

fun TrailerItemResponse.toNetwork(): TrailerItemKinopoisk = TrailerItemKinopoisk(
url = url.orEmpty(),
name = name.orEmpty(),
site = TrailerSiteType.getByValue(site.orEmpty()),
)

fun MovieResponse.toNetwork(): MovieKinopoisk = MovieKinopoisk(
kinopoiskId = kinopoiskId,
kinopoiskHDId = kinopoiskHDId.orEmpty(),
imdbId = imdbId.orEmpty(),
nameRu = nameRu.orEmpty(),
nameEn = nameEn.orEmpty(),
nameOriginal = nameOriginal.orEmpty(),
posterUrl = posterUrl.orEmpty(),
posterUrlPreview = posterUrlPreview.orEmpty(),
coverUrl = coverUrl.orEmpty(),
logoUrl = logoUrl.orEmpty(),
reviewsCount = reviewsCount,
ratingGoodReview = ratingGoodReview,
ratingGoodReviewVoteCount = ratingGoodReviewVoteCount,
ratingKinopoisk = ratingKinopoisk,
ratingKinopoiskVoteCount = ratingKinopoiskVoteCount,
ratingImdb = ratingImdb,
ratingImdbVoteCount = ratingImdbVoteCount,
ratingFilmCritics = ratingFilmCritics,
ratingFilmCriticsVoteCount = ratingFilmCriticsVoteCount,
ratingAwait = ratingAwait,
ratingAwaitCount = ratingAwaitCount,
ratingRfCritics = ratingRfCritics,
ratingRfCriticsVoteCount = ratingRfCriticsVoteCount,
webUrl = webUrl.orEmpty(),
year = year,
filmLength = filmLength,
slogan = slogan.orEmpty(),
description = description,
shortDescription = shortDescription.orEmpty(),
editorAnnotation = editorAnnotation.orEmpty(),
isTicketsAvailable = isTicketsAvailable ?: false,
productionStatus = FilmProductionStatusNetwork.getType(productionStatus.orEmpty()),
type = type,
ratingMpaa = ratingMpaa,
ratingAgeLimits = ratingAgeLimits,
hasImax = hasImax ?: false,
has3D = has3D ?: false,
lastSync = lastSync,
countries = countries?.map { it.country }.orEmpty(),
genres = genres?.map { it.genre }.orEmpty(),
startYear = startYear,
endYear = endYear,
isSerial = serial ?: false,
isShortFilm = shortFilm ?: false,
isCompleted = completed ?: false
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.stslex.wizard.core.network.api.kinopoisk.model.network
package com.stslex.wizard.core.network.api.api.kinopoisk.model.network

data class FilmItemKinopoisk(
val kinopoiskId: Int,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.stslex.wizard.core.network.api.kinopoisk.model.network
package com.stslex.wizard.core.network.api.api.kinopoisk.model.network

data class FilmListKinopoisk(
val total: Int,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.stslex.wizard.core.network.api.kinopoisk.model.network
package com.stslex.wizard.core.network.api.api.kinopoisk.model.network

enum class FilmProductionStatusNetwork(val value: String) {
FILMING("FILMING"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.stslex.wizard.core.network.api.kinopoisk.model.network
package com.stslex.wizard.core.network.api.api.kinopoisk.model.network

enum class FilmTypeNetwork(val value: String) {
FILM("FILM"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.stslex.wizard.core.network.api.kinopoisk.model.network
package com.stslex.wizard.core.network.api.api.kinopoisk.model.network

data class MovieKinopoisk(
val kinopoiskId: Int,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.stslex.wizard.core.network.api.api.kinopoisk.model.network

import com.stslex.wizard.core.network.api.clients.film.model.TrailerSiteType

data class TrailerItemKinopoisk(
val url: String,
val name: String,
val site: TrailerSiteType
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.stslex.wizard.core.network.api.kinopoisk.model.network
package com.stslex.wizard.core.network.api.api.kinopoisk.model.network

data class TrailerKinopoisk(
val total: Int,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.stslex.wizard.core.network.api.kinopoisk.model.request
package com.stslex.wizard.core.network.api.api.kinopoisk.model.request

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.stslex.wizard.core.network.api.kinopoisk.model.response
package com.stslex.wizard.core.network.api.api.kinopoisk.model.response

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.stslex.wizard.core.network.api.kinopoisk.model.response
package com.stslex.wizard.core.network.api.api.kinopoisk.model.response

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.stslex.wizard.core.network.api.kinopoisk.model.response
package com.stslex.wizard.core.network.api.api.kinopoisk.model.response

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.stslex.wizard.core.network.api.kinopoisk.model.response
package com.stslex.wizard.core.network.api.api.kinopoisk.model.response

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.stslex.wizard.core.network.api.kinopoisk.model.response
package com.stslex.wizard.core.network.api.api.kinopoisk.model.response

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.stslex.wizard.core.network.api.kinopoisk.model.response
package com.stslex.wizard.core.network.api.api.kinopoisk.model.response

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.stslex.wizard.core.network.api.kinopoisk.model.response
package com.stslex.wizard.core.network.api.api.kinopoisk.model.response

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.stslex.wizard.core.network.api.api.kinopoisk.source

import com.stslex.wizard.core.network.api.api.kinopoisk.model.network.FilmListKinopoisk
import com.stslex.wizard.core.network.api.api.kinopoisk.model.network.MovieKinopoisk
import com.stslex.wizard.core.network.api.api.kinopoisk.model.network.TrailerKinopoisk

interface KinopoiskNetworkClient {

suspend fun getFilms(page: Int): FilmListKinopoisk

suspend fun getFilm(id: String): MovieKinopoisk

suspend fun getFilmTrailers(id: String): TrailerKinopoisk
}
Loading

0 comments on commit 57a6851

Please sign in to comment.