diff --git a/.github/workflows/lint_checks.yml b/.github/workflows/lint_checks.yml index 2ea1f138..be1e0836 100644 --- a/.github/workflows/lint_checks.yml +++ b/.github/workflows/lint_checks.yml @@ -1,6 +1,6 @@ name: Lint Checks -on: push +on: pull_request jobs: lint-checks: diff --git a/.github/workflows/build.yml b/.github/workflows/unit_tests.yml similarity index 83% rename from .github/workflows/build.yml rename to .github/workflows/unit_tests.yml index 08e456b7..4c0c840d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/unit_tests.yml @@ -1,9 +1,9 @@ -name: Build +name: Unit Tests -on: push +on: pull_request jobs: - build: + unit-tests: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 @@ -19,4 +19,4 @@ jobs: run: echo $LOCAL_PROPERTIES > ./local.properties - name: Build Project - run: ./gradlew assemble \ No newline at end of file + run: ./gradlew build \ No newline at end of file diff --git a/.gitignore b/.gitignore index da23fbb7..f9433175 100644 --- a/.gitignore +++ b/.gitignore @@ -18,5 +18,6 @@ local.properties /feature-eventsummarylist/build/ /team-api/build/ /team-implementation/build/ +/octanegg/build/ /buildSrc/build/ PocketLeagueiOS/PocketLeagueiOS.xcodeproj/project.xcworkspace/xcuserdata/amcneilly.xcuserdatad/UserInterfaceState.xcuserstate diff --git a/app/build.gradle.kts b/app/build.gradle.kts index ab25b9d0..615aca5b 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -81,22 +81,6 @@ android { excludes += "/META-INF/{AL2.0,LGPL2.1}" } } - - testOptions { - unitTests.all { - it.extensions.configure(kotlinx.kover.api.KoverTaskExtension::class) { - isEnabled = true - excludes = listOf( - "dagger.hilt.internal.aggregatedroot.codegen.*", - "hilt_aggregated_deps.*", - ".*ComposableSingletons.*", - ".*Hilt.*", - ".*BuildConfig.*", - ".*_Factory.*", - ) - } - } - } } dependencies { diff --git a/build.gradle.kts b/build.gradle.kts index 94a816da..0e2d240e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,7 +15,6 @@ buildscript { classpath("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.19.0") classpath("com.github.ben-manes:gradle-versions-plugin:0.29.0") classpath("com.google.dagger:hilt-android-gradle-plugin:${Versions.hilt}") - classpath("org.jetbrains.kotlinx:kover:0.4.1") classpath("com.hiya:jacoco-android:0.2") classpath("gradle.plugin.org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.12.0") classpath("org.jetbrains.kotlin:kotlin-serialization:1.6.10") @@ -38,9 +37,8 @@ allprojects { } subprojects { - apply(from = "../buildscripts/ktlint.gradle") - apply(from = "../buildscripts/versionsplugin.gradle") - apply(from = "../buildscripts/kover.gradle") + apply(from = "${rootProject.projectDir}/buildscripts/ktlint.gradle") + apply(from = "${rootProject.projectDir}/buildscripts/versionsplugin.gradle") } tasks.register("clean", Delete::class) { diff --git a/buildscripts/kover.gradle b/buildscripts/kover.gradle deleted file mode 100644 index df9ee0c6..00000000 --- a/buildscripts/kover.gradle +++ /dev/null @@ -1 +0,0 @@ -apply plugin: "kover" \ No newline at end of file diff --git a/event-implementation/build.gradle.kts b/event-implementation/build.gradle.kts index e1760b95..7d5b2a4e 100644 --- a/event-implementation/build.gradle.kts +++ b/event-implementation/build.gradle.kts @@ -3,7 +3,6 @@ import java.util.Properties plugins { kotlin("multiplatform") - kotlin("plugin.serialization") id("com.android.library") id("com.apollographql.apollo3").version(Versions.apollo) id("com.codingfeline.buildkonfig").version(Versions.buildKonfig) @@ -27,6 +26,7 @@ kotlin { dependencies { implementation(project(":event-api")) implementation(project(":core-datetime")) + implementation(project(":octanegg")) implementation("com.apollographql.apollo3:apollo-runtime:${Versions.apollo}") implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2") implementation("io.ktor:ktor-client-core:${Versions.ktor}") @@ -40,11 +40,7 @@ kotlin { implementation(kotlin("test")) } } - val androidMain by getting { - dependencies { - implementation("io.ktor:ktor-client-android:${Versions.ktor}") - } - } + val androidMain by getting val androidTest by getting val iosX64Main by getting val iosArm64Main by getting @@ -54,10 +50,6 @@ kotlin { iosX64Main.dependsOn(this) iosArm64Main.dependsOn(this) iosSimulatorArm64Main.dependsOn(this) - - dependencies { - implementation("io.ktor:ktor-client-ios:${Versions.ktor}") - } } val iosX64Test by getting val iosArm64Test by getting diff --git a/event-implementation/src/commonMain/kotlin/com/adammcneilly/pocketleague/event/implementation/octanegg/OctaneGGEventService.kt b/event-implementation/src/commonMain/kotlin/com/adammcneilly/pocketleague/event/implementation/octanegg/OctaneGGEventService.kt index 87684fca..918187c2 100644 --- a/event-implementation/src/commonMain/kotlin/com/adammcneilly/pocketleague/event/implementation/octanegg/OctaneGGEventService.kt +++ b/event-implementation/src/commonMain/kotlin/com/adammcneilly/pocketleague/event/implementation/octanegg/OctaneGGEventService.kt @@ -3,11 +3,11 @@ package com.adammcneilly.pocketleague.event.implementation.octanegg import com.adammcneilly.pocketleague.core.data.DataResult import com.adammcneilly.pocketleague.core.models.EventOverview import com.adammcneilly.pocketleague.core.models.EventSummary +import com.adammcneilly.pocketleague.data.remote.octanegg.OctaneGGAPIClient +import com.adammcneilly.pocketleague.data.remote.octanegg.dtos.EventDTO +import com.adammcneilly.pocketleague.data.remote.octanegg.dtos.EventListResponseDTO +import com.adammcneilly.pocketleague.data.remote.octanegg.mappers.toEventSummary import com.adammcneilly.pocketleague.event.api.EventRepository -import com.adammcneilly.pocketleague.event.implementation.octanegg.dtos.EventDTO -import com.adammcneilly.pocketleague.event.implementation.octanegg.dtos.EventListResponseDTO -import com.adammcneilly.pocketleague.event.implementation.octanegg.mappers.toEventSummary -import io.ktor.client.request.parameter import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow @@ -25,9 +25,7 @@ class OctaneGGEventService : EventRepository { override fun fetchEventSummaries(): Flow>> { return flow { - val apiResult = apiClient.getResponse("events") { - this.parameter("group", "rlcs2122") - } + val apiResult = apiClient.getResponse("events") val mappedResult: DataResult> = when (apiResult) { is DataResult.Success -> { diff --git a/octanegg/build.gradle.kts b/octanegg/build.gradle.kts new file mode 100644 index 00000000..b5245721 --- /dev/null +++ b/octanegg/build.gradle.kts @@ -0,0 +1,76 @@ +plugins { + kotlin("multiplatform") + kotlin("plugin.serialization") + id("com.android.library") +} + +kotlin { + android() + + listOf( + iosX64(), + iosArm64(), + iosSimulatorArm64() + ).forEach { + it.binaries.framework { + baseName = "octanegg" + } + } + + sourceSets { + val commonMain by getting { + dependencies { + implementation(project(":core-data")) + implementation(project(":core-models")) + implementation(project(":core-datetime")) + implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2") + implementation("io.ktor:ktor-client-core:${Versions.ktor}") + implementation("io.ktor:ktor-client-json:${Versions.ktor}") + implementation("io.ktor:ktor-client-logging:${Versions.ktor}") + implementation("io.ktor:ktor-client-serialization:${Versions.ktor}") + } + } + val commonTest by getting { + dependencies { + implementation(kotlin("test")) + } + } + val androidMain by getting { + dependencies { + implementation("io.ktor:ktor-client-android:${Versions.ktor}") + } + } + val androidTest by getting + val iosX64Main by getting + val iosArm64Main by getting + val iosSimulatorArm64Main by getting + val iosMain by creating { + dependsOn(commonMain) + iosX64Main.dependsOn(this) + iosArm64Main.dependsOn(this) + iosSimulatorArm64Main.dependsOn(this) + + dependencies { + implementation("io.ktor:ktor-client-ios:${Versions.ktor}") + } + } + val iosX64Test by getting + val iosArm64Test by getting + val iosSimulatorArm64Test by getting + val iosTest by creating { + dependsOn(commonTest) + iosX64Test.dependsOn(this) + iosArm64Test.dependsOn(this) + iosSimulatorArm64Test.dependsOn(this) + } + } +} + +android { + compileSdk = AndroidConfig.compileSDK + sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml") + defaultConfig { + minSdk = AndroidConfig.minSDK + targetSdk = AndroidConfig.targetSDK + } +} diff --git a/octanegg/src/androidMain/AndroidManifest.xml b/octanegg/src/androidMain/AndroidManifest.xml new file mode 100644 index 00000000..5377c4ce --- /dev/null +++ b/octanegg/src/androidMain/AndroidManifest.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/event-implementation/src/commonMain/kotlin/com/adammcneilly/pocketleague/event/implementation/octanegg/OctaneGGAPIClient.kt b/octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/OctaneGGAPIClient.kt similarity index 93% rename from event-implementation/src/commonMain/kotlin/com/adammcneilly/pocketleague/event/implementation/octanegg/OctaneGGAPIClient.kt rename to octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/OctaneGGAPIClient.kt index b8d6a24a..e2e81a6c 100644 --- a/event-implementation/src/commonMain/kotlin/com/adammcneilly/pocketleague/event/implementation/octanegg/OctaneGGAPIClient.kt +++ b/octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/OctaneGGAPIClient.kt @@ -1,4 +1,4 @@ -package com.adammcneilly.pocketleague.event.implementation.octanegg +package com.adammcneilly.pocketleague.data.remote.octanegg import com.adammcneilly.pocketleague.core.data.DataResult import io.ktor.client.HttpClient @@ -12,7 +12,7 @@ import kotlinx.serialization.json.Json /** * Defines the API client information for communicating with the octane.gg API. */ -internal class OctaneGGAPIClient { +class OctaneGGAPIClient { val baseURL = "https://zsr.octane.gg/" val httpClient = HttpClient { diff --git a/octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/dtos/AccountDTO.kt b/octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/dtos/AccountDTO.kt new file mode 100644 index 00000000..ccfaa87b --- /dev/null +++ b/octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/dtos/AccountDTO.kt @@ -0,0 +1,15 @@ +package com.adammcneilly.pocketleague.data.remote.octanegg.dtos + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +/** + * Represents a [PlayerDTO] account within the octane.gg API. + */ +@Serializable +data class AccountDTO( + @SerialName("id") + val id: String? = null, + @SerialName("platform") + val platform: String? = null, +) diff --git a/event-implementation/src/commonMain/kotlin/com/adammcneilly/pocketleague/event/implementation/octanegg/dtos/EventDTO.kt b/octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/dtos/EventDTO.kt similarity index 84% rename from event-implementation/src/commonMain/kotlin/com/adammcneilly/pocketleague/event/implementation/octanegg/dtos/EventDTO.kt rename to octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/dtos/EventDTO.kt index e4ce1093..e1b2dcf3 100644 --- a/event-implementation/src/commonMain/kotlin/com/adammcneilly/pocketleague/event/implementation/octanegg/dtos/EventDTO.kt +++ b/octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/dtos/EventDTO.kt @@ -1,4 +1,4 @@ -package com.adammcneilly.pocketleague.event.implementation.octanegg.dtos +package com.adammcneilly.pocketleague.data.remote.octanegg.dtos import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -7,7 +7,7 @@ import kotlinx.serialization.Serializable * A data class mapping to an Event from the octane.gg API. */ @Serializable -internal data class EventDTO( +data class EventDTO( @SerialName("_id") val id: String, val endDate: String? = null, diff --git a/event-implementation/src/commonMain/kotlin/com/adammcneilly/pocketleague/event/implementation/octanegg/dtos/EventListResponseDTO.kt b/octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/dtos/EventListResponseDTO.kt similarity index 66% rename from event-implementation/src/commonMain/kotlin/com/adammcneilly/pocketleague/event/implementation/octanegg/dtos/EventListResponseDTO.kt rename to octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/dtos/EventListResponseDTO.kt index b6f74fdf..6cbde88a 100644 --- a/event-implementation/src/commonMain/kotlin/com/adammcneilly/pocketleague/event/implementation/octanegg/dtos/EventListResponseDTO.kt +++ b/octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/dtos/EventListResponseDTO.kt @@ -1,4 +1,4 @@ -package com.adammcneilly.pocketleague.event.implementation.octanegg.dtos +package com.adammcneilly.pocketleague.data.remote.octanegg.dtos import kotlinx.serialization.Serializable @@ -6,7 +6,7 @@ import kotlinx.serialization.Serializable * A DTO that maps to an event list response from the octane.gg API. */ @Serializable -internal data class EventListResponseDTO( +data class EventListResponseDTO( val events: List, val page: Int, val perPage: Int, diff --git a/event-implementation/src/commonMain/kotlin/com/adammcneilly/pocketleague/event/implementation/octanegg/dtos/LocationDTO.kt b/octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/dtos/LocationDTO.kt similarity index 67% rename from event-implementation/src/commonMain/kotlin/com/adammcneilly/pocketleague/event/implementation/octanegg/dtos/LocationDTO.kt rename to octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/dtos/LocationDTO.kt index 4f8a0af0..6ccc62d4 100644 --- a/event-implementation/src/commonMain/kotlin/com/adammcneilly/pocketleague/event/implementation/octanegg/dtos/LocationDTO.kt +++ b/octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/dtos/LocationDTO.kt @@ -1,4 +1,4 @@ -package com.adammcneilly.pocketleague.event.implementation.octanegg.dtos +package com.adammcneilly.pocketleague.data.remote.octanegg.dtos import kotlinx.serialization.Serializable @@ -6,7 +6,7 @@ import kotlinx.serialization.Serializable * A data class mapping to a location from the octane.gg API. */ @Serializable -internal data class LocationDTO( +data class LocationDTO( val city: String? = null, val country: String? = null, val venue: String? = null, diff --git a/octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/dtos/PlayerDTO.kt b/octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/dtos/PlayerDTO.kt new file mode 100644 index 00000000..869df60a --- /dev/null +++ b/octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/dtos/PlayerDTO.kt @@ -0,0 +1,31 @@ +package com.adammcneilly.pocketleague.data.remote.octanegg.dtos + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +/** + * Represents a person who is a player for a [TeamDTO] in the octane.gg API. + */ +@Serializable +data class PlayerDTO( + @SerialName("accounts") + val accounts: List? = null, + @SerialName("coach") + val coach: Boolean? = null, + @SerialName("country") + val country: String? = null, + @SerialName("_id") + val id: String? = null, + @SerialName("name") + val name: String? = null, + @SerialName("relevant") + val relevant: Boolean? = null, + @SerialName("slug") + val slug: String? = null, + @SerialName("substitute") + val substitute: Boolean? = null, + @SerialName("tag") + val tag: String? = null, + @SerialName("team") + val team: TeamOverviewDTO? = null, +) diff --git a/event-implementation/src/commonMain/kotlin/com/adammcneilly/pocketleague/event/implementation/octanegg/dtos/PrizeDTO.kt b/octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/dtos/PrizeDTO.kt similarity index 66% rename from event-implementation/src/commonMain/kotlin/com/adammcneilly/pocketleague/event/implementation/octanegg/dtos/PrizeDTO.kt rename to octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/dtos/PrizeDTO.kt index 98cace99..0aef283c 100644 --- a/event-implementation/src/commonMain/kotlin/com/adammcneilly/pocketleague/event/implementation/octanegg/dtos/PrizeDTO.kt +++ b/octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/dtos/PrizeDTO.kt @@ -1,4 +1,4 @@ -package com.adammcneilly.pocketleague.event.implementation.octanegg.dtos +package com.adammcneilly.pocketleague.data.remote.octanegg.dtos import kotlinx.serialization.Serializable @@ -6,7 +6,7 @@ import kotlinx.serialization.Serializable * A data class mapping to a prize entity from the octane.gg API. */ @Serializable -internal data class PrizeDTO( +data class PrizeDTO( val amount: Double? = null, val currency: String? = null, ) diff --git a/event-implementation/src/commonMain/kotlin/com/adammcneilly/pocketleague/event/implementation/octanegg/dtos/StageDTO.kt b/octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/dtos/StageDTO.kt similarity index 82% rename from event-implementation/src/commonMain/kotlin/com/adammcneilly/pocketleague/event/implementation/octanegg/dtos/StageDTO.kt rename to octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/dtos/StageDTO.kt index f1d478de..3e408912 100644 --- a/event-implementation/src/commonMain/kotlin/com/adammcneilly/pocketleague/event/implementation/octanegg/dtos/StageDTO.kt +++ b/octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/dtos/StageDTO.kt @@ -1,4 +1,4 @@ -package com.adammcneilly.pocketleague.event.implementation.octanegg.dtos +package com.adammcneilly.pocketleague.data.remote.octanegg.dtos import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -7,7 +7,7 @@ import kotlinx.serialization.Serializable * A data class mapping to a stage from the octane.gg API. */ @Serializable -internal data class StageDTO( +data class StageDTO( @SerialName("_id") val id: Int, val endDate: String? = null, diff --git a/octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/dtos/TeamDTO.kt b/octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/dtos/TeamDTO.kt new file mode 100644 index 00000000..d080aa38 --- /dev/null +++ b/octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/dtos/TeamDTO.kt @@ -0,0 +1,15 @@ +package com.adammcneilly.pocketleague.data.remote.octanegg.dtos + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +/** + * Represents a team within the octane.gg API domain. + */ +@Serializable +data class TeamDTO( + @SerialName("players") + val players: List? = null, + @SerialName("team") + val team: TeamOverviewDTO? = null, +) diff --git a/octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/dtos/TeamListResponseDTO.kt b/octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/dtos/TeamListResponseDTO.kt new file mode 100644 index 00000000..8d654aa1 --- /dev/null +++ b/octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/dtos/TeamListResponseDTO.kt @@ -0,0 +1,19 @@ +package com.adammcneilly.pocketleague.data.remote.octanegg.dtos + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +/** + * A data response for a list of teams within the octane.gg API. + */ +@Serializable +data class TeamListResponseDTO( + @SerialName("teams") + val teams: List? = null, + @SerialName("page") + val page: Int? = null, + @SerialName("perPage") + val perPage: Int? = null, + @SerialName("pageSize") + val pageSize: Int? = null, +) diff --git a/octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/dtos/TeamOverviewDTO.kt b/octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/dtos/TeamOverviewDTO.kt new file mode 100644 index 00000000..faa992ae --- /dev/null +++ b/octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/dtos/TeamOverviewDTO.kt @@ -0,0 +1,23 @@ +package com.adammcneilly.pocketleague.data.remote.octanegg.dtos + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +/** + * Overview information about a team, that does not include roster info. + */ +@Serializable +data class TeamOverviewDTO( + @SerialName("_id") + val id: String? = null, + @SerialName("image") + val image: String? = null, + @SerialName("name") + val name: String? = null, + @SerialName("region") + val region: String? = null, + @SerialName("relevant") + val relevant: Boolean? = null, + @SerialName("slug") + val slug: String? = null, +) diff --git a/event-implementation/src/commonMain/kotlin/com/adammcneilly/pocketleague/event/implementation/octanegg/mappers/EventSummaryMapper.kt b/octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/mappers/EventSummaryMapper.kt similarity index 72% rename from event-implementation/src/commonMain/kotlin/com/adammcneilly/pocketleague/event/implementation/octanegg/mappers/EventSummaryMapper.kt rename to octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/mappers/EventSummaryMapper.kt index 4b09082b..7fc3ec08 100644 --- a/event-implementation/src/commonMain/kotlin/com/adammcneilly/pocketleague/event/implementation/octanegg/mappers/EventSummaryMapper.kt +++ b/octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/mappers/EventSummaryMapper.kt @@ -1,14 +1,14 @@ -package com.adammcneilly.pocketleague.event.implementation.octanegg.mappers +package com.adammcneilly.pocketleague.data.remote.octanegg.mappers import com.adammcneilly.pocketleague.core.datetime.DateTimeParser import com.adammcneilly.pocketleague.core.models.EventSummary -import com.adammcneilly.pocketleague.event.implementation.octanegg.dtos.EventDTO +import com.adammcneilly.pocketleague.data.remote.octanegg.dtos.EventDTO import kotlinx.datetime.TimeZone /** * Converts an [EventDTO] from octane.gg into an [EventSummary]. */ -internal fun EventDTO.toEventSummary(): EventSummary { +fun EventDTO.toEventSummary(): EventSummary { return EventSummary( id = this.id, eventName = this.name ?: "N/A", diff --git a/octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/mappers/PlayerMapper.kt b/octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/mappers/PlayerMapper.kt new file mode 100644 index 00000000..7d068025 --- /dev/null +++ b/octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/mappers/PlayerMapper.kt @@ -0,0 +1,15 @@ +package com.adammcneilly.pocketleague.data.remote.octanegg.mappers + +import com.adammcneilly.pocketleague.core.models.Player +import com.adammcneilly.pocketleague.data.remote.octanegg.dtos.PlayerDTO + +/** + * Converts a [PlayerDTO] from octane.gg API into a [Player] entity. + */ +fun PlayerDTO.toPlayer(): Player { + return Player( + countryCode = this.country ?: "N/A", + gamerTag = this.tag ?: "N/A", + realName = this.name ?: "N/A", + ) +} diff --git a/octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/mappers/TeamMapper.kt b/octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/mappers/TeamMapper.kt new file mode 100644 index 00000000..780594a5 --- /dev/null +++ b/octanegg/src/commonMain/kotlin/com/adammcneilly/pocketleague/data/remote/octanegg/mappers/TeamMapper.kt @@ -0,0 +1,17 @@ +package com.adammcneilly.pocketleague.data.remote.octanegg.mappers + +import com.adammcneilly.pocketleague.core.models.Team +import com.adammcneilly.pocketleague.data.remote.octanegg.dtos.PlayerDTO +import com.adammcneilly.pocketleague.data.remote.octanegg.dtos.TeamDTO + +/** + * Converts a [TeamDTO] from the octane.gg API to a [Team] entity. + */ +fun TeamDTO.toTeam(): Team { + return Team( + name = this.team?.name ?: "N/A", + lightThemeLogoImageUrl = this.team?.image, + darkThemeLogoImageUrl = this.team?.image, + roster = this.players?.map(PlayerDTO::toPlayer).orEmpty(), + ) +} diff --git a/settings.gradle b/settings.gradle index 06a67a39..071ec964 100644 --- a/settings.gradle +++ b/settings.gradle @@ -10,3 +10,4 @@ include ':feature-eventsummarylist' include ':core-datetime' include ':team-api' include ':team-implementation' +include ':octanegg' diff --git a/team-implementation/build.gradle.kts b/team-implementation/build.gradle.kts index a63b182b..8e58ce14 100644 --- a/team-implementation/build.gradle.kts +++ b/team-implementation/build.gradle.kts @@ -1,6 +1,5 @@ plugins { kotlin("multiplatform") - kotlin("plugin.serialization") id("com.android.library") } @@ -21,6 +20,7 @@ kotlin { val commonMain by getting { dependencies { implementation(project(":team-api")) + implementation(project(":octanegg")) implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2") implementation("io.ktor:ktor-client-core:${Versions.ktor}") implementation("io.ktor:ktor-client-json:${Versions.ktor}") @@ -33,11 +33,7 @@ kotlin { implementation(kotlin("test")) } } - val androidMain by getting { - dependencies { - implementation("io.ktor:ktor-client-android:${Versions.ktor}") - } - } + val androidMain by getting val androidTest by getting val iosX64Main by getting val iosArm64Main by getting @@ -47,10 +43,6 @@ kotlin { iosX64Main.dependsOn(this) iosArm64Main.dependsOn(this) iosSimulatorArm64Main.dependsOn(this) - - dependencies { - implementation("io.ktor:ktor-client-ios:${Versions.ktor}") - } } val iosX64Test by getting val iosArm64Test by getting diff --git a/team-implementation/src/commonMain/kotlin/com/adammcneilly/pocketleague/team/implementation/octanegg/OctaneGGTeamService.kt b/team-implementation/src/commonMain/kotlin/com/adammcneilly/pocketleague/team/implementation/octanegg/OctaneGGTeamService.kt index 884de3ab..0b1ca5b0 100644 --- a/team-implementation/src/commonMain/kotlin/com/adammcneilly/pocketleague/team/implementation/octanegg/OctaneGGTeamService.kt +++ b/team-implementation/src/commonMain/kotlin/com/adammcneilly/pocketleague/team/implementation/octanegg/OctaneGGTeamService.kt @@ -2,10 +2,11 @@ package com.adammcneilly.pocketleague.team.implementation.octanegg import com.adammcneilly.pocketleague.core.data.DataResult import com.adammcneilly.pocketleague.core.models.Team +import com.adammcneilly.pocketleague.data.remote.octanegg.OctaneGGAPIClient +import com.adammcneilly.pocketleague.data.remote.octanegg.dtos.TeamDTO +import com.adammcneilly.pocketleague.data.remote.octanegg.dtos.TeamListResponseDTO +import com.adammcneilly.pocketleague.data.remote.octanegg.mappers.toTeam import com.adammcneilly.pocketleague.team.api.TeamRepository -import com.adammcneilly.pocketleague.team.implementation.octanegg.dtos.TeamDTO -import com.adammcneilly.pocketleague.team.implementation.octanegg.dtos.TeamListResponseDTO -import com.adammcneilly.pocketleague.team.implementation.octanegg.mappers.toTeam import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow