-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Mohsen <[email protected]>
- Loading branch information
Showing
9 changed files
with
144 additions
and
90 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
28 changes: 28 additions & 0 deletions
28
composeApp/src/commonMain/kotlin/episodes/data/EpisodesRemoteDataSource.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,28 @@ | ||
package episodes.data | ||
|
||
import io.ktor.client.HttpClient | ||
import io.ktor.client.call.body | ||
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation | ||
import io.ktor.client.request.get | ||
import io.ktor.client.request.parameter | ||
import io.ktor.serialization.kotlinx.json.json | ||
|
||
class EpisodesRemoteDataSource { | ||
|
||
private val httpClient = HttpClient { | ||
install(ContentNegotiation) { | ||
json() | ||
} | ||
} | ||
|
||
suspend fun fetchEpisodes(page: Int): Response = | ||
httpClient | ||
.get("https://rickandmortyapi.com/api/episode") { | ||
parameter("page", page) | ||
} | ||
.body<Response>() | ||
|
||
fun close() { | ||
httpClient.close() | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
composeApp/src/commonMain/kotlin/episodes/data/EpisodesRepositoryImpl.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,26 @@ | ||
package episodes.data | ||
|
||
import episodes.domain.Episode | ||
import episodes.domain.EpisodesRepository | ||
|
||
internal class EpisodesRepositoryImpl( | ||
private val remote: EpisodesRemoteDataSource, | ||
) : EpisodesRepository { | ||
|
||
override suspend fun getEpisodes(page: Int): List<Episode> { | ||
return remote.fetchEpisodes(page).results.map { | ||
Episode( | ||
id = it.id, | ||
name = it.name, | ||
airDate = it.airDate, | ||
episode = it.episode, | ||
characters = it.characters, | ||
created = it.created, | ||
) | ||
} | ||
} | ||
|
||
override fun close() { | ||
remote.close() | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
composeApp/src/commonMain/kotlin/episodes/domain/EpisodesRepository.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 episodes.domain | ||
|
||
interface EpisodesRepository { | ||
suspend fun getEpisodes(page: Int): List<Episode> | ||
fun close() | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,57 @@ | ||
[versions] | ||
compose = "1.5.4" | ||
compose-plugin = "1.5.11" | ||
compose-compiler = "1.5.5" | ||
agp = "8.1.4" | ||
android-minSdk = "24" | ||
android-compileSdk = "34" | ||
android-targetSdk = "34" | ||
androidx-activityCompose = "1.8.1" | ||
androidx-core-ktx = "1.12.0" | ||
androidx-appcompat = "1.6.1" | ||
androidx-material = "1.10.0" | ||
androidx-constraintlayout = "2.1.4" | ||
androidx-test-junit = "1.1.5" | ||
androidx-espresso-core = "3.5.1" | ||
kotlin = "1.9.21" | ||
kotlinx-couroutines = "1.7.3" | ||
junit = "4.13.2" | ||
ktor = "2.3.6" | ||
moko-mvvm = "0.16.1" | ||
kamel = "0.8.3" | ||
|
||
[libraries] | ||
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" } | ||
kotlin-test-junit = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlin" } | ||
junit = { group = "junit", name = "junit", version.ref = "junit" } | ||
compose-ui = { module = "androidx.compose.ui:ui", version.ref = "compose" } | ||
compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "compose" } | ||
compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "compose" } | ||
compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "compose" } | ||
compose-material3 = { module = "androidx.compose.material3:material3", version.ref = "compose" } | ||
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "androidx-core-ktx" } | ||
androidx-test-junit = { group = "androidx.test.ext", name = "junit", version.ref = "androidx-test-junit" } | ||
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "androidx-espresso-core" } | ||
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "androidx-appcompat" } | ||
androidx-material3 = { group = "com.google.android.material", name = "material", version.ref = "androidx-material" } | ||
androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "androidx-constraintlayout" } | ||
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" } | ||
ktor-client-content-negotiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktor" } | ||
ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" } | ||
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" } | ||
ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktor" } | ||
ktor-client-darwin = { module = "io.ktor:ktor-client-darwin", version.ref = "ktor" } | ||
moko-mvvm-core = { module = "dev.icerock.moko:mvvm-core", version.ref = "moko-mvvm" } | ||
moko-mvvm-compose = { module = "dev.icerock.moko:mvvm-compose", version.ref = "moko-mvvm" } | ||
kamel = { module = "media.kamel:kamel-image", version.ref = "kamel" } | ||
|
||
[plugins] | ||
jetbrainsCompose = { id = "org.jetbrains.compose", version.ref = "compose-plugin" } | ||
androidApplication = { id = "com.android.application", version.ref = "agp" } | ||
androidLibrary = { id = "com.android.library", version.ref = "agp" } | ||
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } | ||
kotlinXSerialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } | ||
[versions] | ||
compose = "1.5.4" | ||
compose-plugin = "1.5.11" | ||
compose-compiler = "1.5.5" | ||
agp = "8.1.4" | ||
android-minSdk = "24" | ||
android-compileSdk = "34" | ||
android-targetSdk = "34" | ||
androidx-activityCompose = "1.8.1" | ||
androidx-core-ktx = "1.12.0" | ||
androidx-appcompat = "1.6.1" | ||
androidx-material = "1.10.0" | ||
androidx-constraintlayout = "2.1.4" | ||
androidx-test-junit = "1.1.5" | ||
androidx-espresso-core = "3.5.1" | ||
kotlin = "1.9.21" | ||
kotlinx-couroutines = "1.7.3" | ||
junit = "4.13.2" | ||
koin = "3.2.0" | ||
ktor = "2.3.6" | ||
moko-mvvm = "0.16.1" | ||
kamel = "0.8.3" | ||
|
||
[libraries] | ||
kotlin-test = { module = "org.jetbrains.kotlin", name = "kotlin-test", version.ref = "kotlin" } | ||
kotlin-test-junit = { module = "org.jetbrains.kotlin", name = "kotlin-test-junit", version.ref = "kotlin" } | ||
junit = { group = "junit", name = "junit", version.ref = "junit" } | ||
compose-ui = { module = "androidx.compose.ui", name = "ui", version.ref = "compose" } | ||
compose-ui-tooling = { module = "androidx.compose.ui", name = "ui-tooling", version.ref = "compose" } | ||
compose-ui-tooling-preview = { module = "androidx.compose.ui", name = "ui-tooling-preview", version.ref = "compose" } | ||
compose-foundation = { module = "androidx.compose.foundation", name = "foundation", version.ref = "compose" } | ||
compose-material3 = { module = "androidx.compose.material3", name = "material3", version.ref = "compose" } | ||
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "androidx-core-ktx" } | ||
androidx-test-junit = { group = "androidx.test.ext", name = "junit", version.ref = "androidx-test-junit" } | ||
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "androidx-espresso-core" } | ||
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "androidx-appcompat" } | ||
androidx-material3 = { group = "com.google.android.material", name = "material", version.ref = "androidx-material" } | ||
androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "androidx-constraintlayout" } | ||
androidx-activity-compose = { module = "androidx.activity", name = "activity-compose", version.ref = "androidx-activityCompose" } | ||
koin-core = { module = "io.insert-koin", name = "koin-core", version.ref = "koin" } | ||
koin-test = { module = "io.insert-koin", name = "koin-test", version.ref = "koin" } | ||
koin-android = { module = "io.insert-koin", name = "koin-android", version.ref = "koin" } | ||
ktor-client-content-negotiation = { module = "io.ktor", name = "ktor-client-content-negotiation", version.ref = "ktor" } | ||
ktor-serialization-kotlinx-json = { module = "io.ktor", name = "ktor-serialization-kotlinx-json", version.ref = "ktor" } | ||
ktor-client-core = { module = "io.ktor", name = "ktor-client-core", version.ref = "ktor" } | ||
ktor-client-okhttp = { module = "io.ktor", name = "ktor-client-okhttp", version.ref = "ktor" } | ||
ktor-client-darwin = { module = "io.ktor", name = "ktor-client-darwin", version.ref = "ktor" } | ||
moko-mvvm-core = { module = "dev.icerock.moko", name = "mvvm-core", version.ref = "moko-mvvm" } | ||
moko-mvvm-compose = { module = "dev.icerock.moko", name = "mvvm-compose", version.ref = "moko-mvvm" } | ||
kamel = { module = "media.kamel", name = "kamel-image", version.ref = "kamel" } | ||
|
||
[plugins] | ||
jetbrainsCompose = { id = "org.jetbrains.compose", version.ref = "compose-plugin" } | ||
androidApplication = { id = "com.android.application", version.ref = "agp" } | ||
androidLibrary = { id = "com.android.library", version.ref = "agp" } | ||
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } | ||
kotlinXSerialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } |