diff --git a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/models/CoreStats.kt b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/models/CoreStats.kt index cb173ee2..7a284fcd 100644 --- a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/models/CoreStats.kt +++ b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/models/CoreStats.kt @@ -4,10 +4,10 @@ package com.adammcneilly.pocketleague.shared.app.core.models * The core statistics for a player or team within a match or game. */ data class CoreStats( - val shots: Int = 0, - val goals: Int = 0, - val saves: Int = 0, - val assists: Int = 0, - val score: Int = 0, - val shootingPercentage: Float = 0F, + val shots: Int, + val goals: Int, + val saves: Int, + val assists: Int, + val score: Int, + val shootingPercentage: Float, ) diff --git a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/models/Format.kt b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/models/Format.kt index 336c523f..ae139c0f 100644 --- a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/models/Format.kt +++ b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/models/Format.kt @@ -5,8 +5,8 @@ package com.adammcneilly.pocketleague.shared.app.core.models * For a best of 7, we would have something like (type: best, length: 7) */ data class Format( - val type: String = "", - val length: Int = 0, + val type: String, + val length: Int, ) { /** * Depending on the [type] of format, return the number of games diff --git a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/models/Game.kt b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/models/Game.kt index 9298a1d1..76a166f6 100644 --- a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/models/Game.kt +++ b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/models/Game.kt @@ -4,12 +4,12 @@ package com.adammcneilly.pocketleague.shared.app.core.models * Information about a single [Game] inside a [Match] between two teams. */ data class Game( - val id: String = "", - val blue: GameTeamResult = GameTeamResult(), - val orange: GameTeamResult = GameTeamResult(), - val map: String = "", - val number: Int = 0, - val duration: Int = GAME_DEFAULT_DURATION_SECONDS, + val id: String, + val blue: GameTeamResult, + val orange: GameTeamResult, + val map: String, + val number: Int, + val duration: Int, ) { companion object { /** diff --git a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/models/GameOverview.kt b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/models/GameOverview.kt index 9cbbd5a3..64038954 100644 --- a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/models/GameOverview.kt +++ b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/models/GameOverview.kt @@ -7,8 +7,8 @@ package com.adammcneilly.pocketleague.shared.app.core.models * For detailed info, we can look it up by [id]. */ data class GameOverview( - val id: String = "", - val blueScore: Int = 0, - val orangeScore: Int = 0, - val durationSeconds: Int = 0, + val id: String, + val blueScore: Int, + val orangeScore: Int, + val durationSeconds: Int, ) diff --git a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/models/GameTeamResult.kt b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/models/GameTeamResult.kt index d084c893..01dbce8a 100644 --- a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/models/GameTeamResult.kt +++ b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/models/GameTeamResult.kt @@ -1,7 +1,7 @@ package com.adammcneilly.pocketleague.shared.app.core.models /** - * Defines information about the reuslt of a [team] within a game. + * Defines information about the result of a [team] within a game. * * @property[goals] The number of goals scored by this team during the game. * @property[winner] True if this team won the specific game. @@ -11,10 +11,10 @@ package com.adammcneilly.pocketleague.shared.app.core.models * @property[players] The players for this [team] and how they performed in this game. */ data class GameTeamResult( - val goals: Int = -1, - val winner: Boolean = false, - val matchWinner: Boolean = false, - val team: Team = Team(), - val teamStats: Stats = Stats(), - val players: List = emptyList(), + val goals: Int, + val winner: Boolean, + val matchWinner: Boolean, + val team: Team, + val teamStats: Stats, + val players: List, ) diff --git a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/models/MatchTeamResult.kt b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/models/MatchTeamResult.kt index 0d3f4eef..9ec1268a 100644 --- a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/models/MatchTeamResult.kt +++ b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/models/MatchTeamResult.kt @@ -4,9 +4,9 @@ package com.adammcneilly.pocketleague.shared.app.core.models * The result of a particular [team] within a [Match]. */ data class MatchTeamResult( - val score: Int = 0, - val winner: Boolean = false, - val team: Team = Team(), - val players: List = emptyList(), - val stats: Stats? = null, + val score: Int, + val winner: Boolean, + val team: Team, + val players: List, + val stats: Stats?, ) diff --git a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/models/Player.kt b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/models/Player.kt index 45dffb87..8af33a69 100644 --- a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/models/Player.kt +++ b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/models/Player.kt @@ -4,12 +4,12 @@ package com.adammcneilly.pocketleague.shared.app.core.models * Represents a person who can compete in an RLCS event. */ data class Player( - val id: String = "", - val slug: String = "", - val tag: String = "", - val name: String = "", - val currentTeamId: String = "", - val countryCode: String = "", - val isCoach: Boolean = false, - val isSubstitute: Boolean = false, + val id: String, + val slug: String, + val tag: String, + val name: String, + val currentTeamId: String, + val countryCode: String, + val isCoach: Boolean, + val isSubstitute: Boolean, ) diff --git a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/models/Stats.kt b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/models/Stats.kt index dbcd94ff..b667e6ea 100644 --- a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/models/Stats.kt +++ b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/models/Stats.kt @@ -4,5 +4,5 @@ package com.adammcneilly.pocketleague.shared.app.core.models * A collection of different types of statistics for a player or team. */ data class Stats( - val core: CoreStats = CoreStats(), + val core: CoreStats, ) diff --git a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/models/Team.kt b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/models/Team.kt index 93982760..c5db661d 100644 --- a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/models/Team.kt +++ b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/core/models/Team.kt @@ -5,11 +5,11 @@ package com.adammcneilly.pocketleague.shared.app.core.models * League event. */ data class Team( - val id: String = "", - val name: String = "TBD", - val lightThemeImageURL: String? = null, + val id: String, + val name: String, + val isFavorite: Boolean, + val isActive: Boolean, + val region: Region, + val lightThemeImageURL: String?, val darkThemeImageURL: String? = lightThemeImageURL, - val isFavorite: Boolean = false, - val isActive: Boolean = false, - val region: Region = Region.Unknown, ) diff --git a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/data/octanegg/dto/OctaneGGGame.kt b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/data/octanegg/dto/OctaneGGGame.kt index bd90b589..10aae7e9 100644 --- a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/data/octanegg/dto/OctaneGGGame.kt +++ b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/data/octanegg/dto/OctaneGGGame.kt @@ -1,7 +1,6 @@ package com.adammcneilly.pocketleague.shared.app.data.octanegg.dto import com.adammcneilly.pocketleague.shared.app.core.models.Game -import com.adammcneilly.pocketleague.shared.app.core.models.GameTeamResult import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -35,6 +34,14 @@ data class OctaneGGGame( * Converts an [OctaneGGGame] to a [Game] in our domain. */ fun toGame(): Game { + requireNotNull(this.blue) { + "Cannot parse OctaneGGGame without blue team entity." + } + + requireNotNull(this.orange) { + "Cannot parse OctaneGGGame without orange team entity." + } + // Currently the octane.gg api does not include a map name for // this map ID, so let's override it ourselves. val mapName = when (this.map?.id) { @@ -44,8 +51,8 @@ data class OctaneGGGame( return Game( id = this.id.orEmpty(), - blue = this.blue?.toGameTeamResult() ?: GameTeamResult(), - orange = this.orange?.toGameTeamResult() ?: GameTeamResult(), + blue = this.blue.toGameTeamResult(), + orange = this.orange.toGameTeamResult(), map = mapName, number = this.number ?: 0, duration = this.duration ?: Game.GAME_DEFAULT_DURATION_SECONDS, diff --git a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/data/octanegg/dto/OctaneGGGameTeamResult.kt b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/data/octanegg/dto/OctaneGGGameTeamResult.kt index 593fb9f9..342ac51d 100644 --- a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/data/octanegg/dto/OctaneGGGameTeamResult.kt +++ b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/data/octanegg/dto/OctaneGGGameTeamResult.kt @@ -1,8 +1,6 @@ package com.adammcneilly.pocketleague.shared.app.data.octanegg.dto import com.adammcneilly.pocketleague.shared.app.core.models.GameTeamResult -import com.adammcneilly.pocketleague.shared.app.core.models.Stats -import com.adammcneilly.pocketleague.shared.app.core.models.Team import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -24,12 +22,24 @@ data class OctaneGGGameTeamResult( * Convert an [OctaneGGGameTeamResult] to a [GameTeamResult] in our domain. */ fun toGameTeamResult(): GameTeamResult { + requireNotNull(this.team) { + "Cannot parse OctaneGGGameTeamResult without team entity." + } + + requireNotNull(this.team.team) { + "Cannot parse OctaneGGGameTeamResult without inner team entity." + } + + requireNotNull(this.team.stats) { + "Cannot parse OctaneGGGameTeamResult without stats entity." + } + return GameTeamResult( - goals = this.team?.stats?.core?.goals ?: 0, + goals = this.team.stats.core?.goals ?: 0, winner = this.gameWinner == true, - team = this.team?.team?.toTeam() ?: Team(), + team = this.team.team.toTeam(), matchWinner = this.matchWinner == true, - teamStats = this.team?.stats?.toStats() ?: Stats(), + teamStats = this.team.stats.toStats(), players = this.players?.map(OctaneGGPlayerStats::toGamePlayerResult).orEmpty(), ) } diff --git a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/data/octanegg/dto/OctaneGGMatch.kt b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/data/octanegg/dto/OctaneGGMatch.kt index 50a028b9..4b4440c3 100644 --- a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/data/octanegg/dto/OctaneGGMatch.kt +++ b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/data/octanegg/dto/OctaneGGMatch.kt @@ -1,10 +1,6 @@ package com.adammcneilly.pocketleague.shared.app.data.octanegg.dto -import com.adammcneilly.pocketleague.shared.app.core.models.Event -import com.adammcneilly.pocketleague.shared.app.core.models.EventStage -import com.adammcneilly.pocketleague.shared.app.core.models.Format import com.adammcneilly.pocketleague.shared.app.core.models.Match -import com.adammcneilly.pocketleague.shared.app.core.models.MatchTeamResult import com.adammcneilly.pocketleague.shared.app.core.models.StageRound import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -37,14 +33,34 @@ data class OctaneGGMatch( * Converts an [OctaneGGMatch] to a [Match] in our domain. */ fun toMatch(): Match { + requireNotNull(this.event) { + "Cannot parse OctaneGGMatch without event entity." + } + + requireNotNull(this.blue) { + "Cannot parse OctaneGGMatch without blue team entity." + } + + requireNotNull(this.orange) { + "Cannot parse OctaneGGMatch without orange team entity." + } + + requireNotNull(this.stage) { + "Cannot parse OctaneGGMatch without stage entity." + } + + requireNotNull(this.format) { + "Cannot parse OctaneGGMatch without format entity." + } + return Match( id = this.id.orEmpty(), - event = this.event?.toEvent() ?: Event(), + event = this.event.toEvent(), dateUTC = this.dateUTC, - blueTeam = this.blue?.toMatchTeamResult() ?: MatchTeamResult(), - orangeTeam = this.orange?.toMatchTeamResult() ?: MatchTeamResult(), - stage = this.stage?.toEventStage() ?: EventStage(), - format = this.format?.toFormat() ?: Format(), + blueTeam = this.blue.toMatchTeamResult(), + orangeTeam = this.orange.toMatchTeamResult(), + stage = this.stage.toEventStage(), + format = this.format.toFormat(), gameOverviews = this.games?.map(OctaneGGGameOverview::toGameOverview).orEmpty(), // Octane.GG API has no concept of a stage round, so we'll just return a default here. round = StageRound(0, ""), diff --git a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/data/octanegg/dto/OctaneGGMatchTeamResult.kt b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/data/octanegg/dto/OctaneGGMatchTeamResult.kt index 09258261..e0354e1d 100644 --- a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/data/octanegg/dto/OctaneGGMatchTeamResult.kt +++ b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/data/octanegg/dto/OctaneGGMatchTeamResult.kt @@ -1,7 +1,6 @@ package com.adammcneilly.pocketleague.shared.app.data.octanegg.dto import com.adammcneilly.pocketleague.shared.app.core.models.MatchTeamResult -import com.adammcneilly.pocketleague.shared.app.core.models.Team import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -28,11 +27,19 @@ data class OctaneGGMatchTeamResult( * Converts an [OctaneGGMatchTeamResult] to a [MatchTeamResult] in our domain. */ fun toMatchTeamResult(): MatchTeamResult { + requireNotNull(this.team) { + "Cannot parse OctaneGGMatchTeamResult without team entity." + } + + requireNotNull(this.team.team) { + "Cannot parse OctaneGGMatchTeamResult without inner team entity." + } + return MatchTeamResult( score = this.score ?: 0, winner = this.winner ?: false, - team = this.team?.team?.toTeam() ?: Team(), - stats = this.team?.stats?.toStats(), + team = this.team.team.toTeam(), + stats = this.team.stats?.toStats(), players = this.players?.map(OctaneGGPlayerStats::toGamePlayerResult).orEmpty(), ) } diff --git a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/data/octanegg/dto/OctaneGGPlayerStats.kt b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/data/octanegg/dto/OctaneGGPlayerStats.kt index 084b0f8d..7d0d028e 100644 --- a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/data/octanegg/dto/OctaneGGPlayerStats.kt +++ b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/data/octanegg/dto/OctaneGGPlayerStats.kt @@ -1,8 +1,6 @@ package com.adammcneilly.pocketleague.shared.app.data.octanegg.dto import com.adammcneilly.pocketleague.shared.app.core.models.GamePlayerResult -import com.adammcneilly.pocketleague.shared.app.core.models.Player -import com.adammcneilly.pocketleague.shared.app.core.models.Stats import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -26,9 +24,17 @@ data class OctaneGGPlayerStats( * can represent a player and their stats in any situation. */ fun toGamePlayerResult(): GamePlayerResult { + requireNotNull(this.player) { + "Cannot parse OctaneGGPlayerStats without player entity." + } + + requireNotNull(this.stats) { + "Cannot parse OctaneGGPlayerStats without stats entity." + } + return GamePlayerResult( - player = this.player?.toPlayer() ?: Player(), - stats = this.stats?.toStats() ?: Stats(), + player = this.player.toPlayer(), + stats = this.stats.toStats(), ) } } diff --git a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/data/octanegg/dto/OctaneGGStats.kt b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/data/octanegg/dto/OctaneGGStats.kt index 1aacc460..5b7988ce 100644 --- a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/data/octanegg/dto/OctaneGGStats.kt +++ b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/data/octanegg/dto/OctaneGGStats.kt @@ -1,6 +1,5 @@ package com.adammcneilly.pocketleague.shared.app.data.octanegg.dto -import com.adammcneilly.pocketleague.shared.app.core.models.CoreStats import com.adammcneilly.pocketleague.shared.app.core.models.Stats import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -25,8 +24,12 @@ data class OctaneGGStats( * Converts an [OctaneGGStats] entity to a [Stats] entity. */ fun toStats(): Stats { + requireNotNull(this.core) { + "Cannot parse OctaneGGStats without core entity." + } + return Stats( - core = this.core?.toCoreStats() ?: CoreStats(), + core = this.core.toCoreStats(), ) } } diff --git a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/data/octanegg/dto/OctaneGGTeamDetail.kt b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/data/octanegg/dto/OctaneGGTeamDetail.kt index 87aa00dd..e3297c61 100644 --- a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/data/octanegg/dto/OctaneGGTeamDetail.kt +++ b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/data/octanegg/dto/OctaneGGTeamDetail.kt @@ -18,6 +18,10 @@ data class OctaneGGTeamDetail( * Converts an [OctaneGGTeamDetail] entity to a [Team] in our domain. */ fun toTeam(): Team { - return this.team?.toTeam() ?: Team() + requireNotNull(team) { + "Cannot parse OctaneGGTeamDetail without team entity." + } + + return this.team.toTeam() } } diff --git a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/data/octanegg/dto/OctaneGGTeamOverview.kt b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/data/octanegg/dto/OctaneGGTeamOverview.kt index 7ea6c67e..6992cce6 100644 --- a/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/data/octanegg/dto/OctaneGGTeamOverview.kt +++ b/shared/app/src/commonMain/kotlin/com/adammcneilly/pocketleague/shared/app/data/octanegg/dto/OctaneGGTeamOverview.kt @@ -33,6 +33,8 @@ data class OctaneGGTeamOverview( name = this.name ?: "TBD", lightThemeImageURL = this.image, region = OctaneGGRegionMapper.fromString(this.region.orEmpty()), + isFavorite = false, + isActive = false, ) } }