Skip to content

Commit

Permalink
Requiring certain params from octane api in models. (#578)
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamMc331 authored Dec 1, 2024
1 parent 3f13a45 commit 9e87a8f
Show file tree
Hide file tree
Showing 17 changed files with 127 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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<GamePlayerResult> = emptyList(),
val goals: Int,
val winner: Boolean,
val matchWinner: Boolean,
val team: Team,
val teamStats: Stats,
val players: List<GamePlayerResult>,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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<GamePlayerResult> = emptyList(),
val stats: Stats? = null,
val score: Int,
val winner: Boolean,
val team: Team,
val players: List<GamePlayerResult>,
val stats: Stats?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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) {
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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(),
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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, ""),
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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(),
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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(),
)
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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(),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ data class OctaneGGTeamOverview(
name = this.name ?: "TBD",
lightThemeImageURL = this.image,
region = OctaneGGRegionMapper.fromString(this.region.orEmpty()),
isFavorite = false,
isActive = false,
)
}
}

0 comments on commit 9e87a8f

Please sign in to comment.