feat: Implement filtering for regular matches and update related functionalities
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 48s
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 48s
This commit is contained in:
@@ -80,6 +80,12 @@ class MatchesApi(
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun updateFriendlyMatchPlayers(clubId: Int, matchId: Int, body: UpdateMatchPlayersBody) {
|
||||
client.http.patch("/api/friendly-matches/$clubId/$matchId/players") {
|
||||
setBody(body)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun deleteFriendlyMatch(clubId: Int, matchId: Int) {
|
||||
client.http.delete("/api/friendly-matches/$clubId/$matchId")
|
||||
}
|
||||
|
||||
@@ -59,6 +59,8 @@ data class ScheduleState(
|
||||
get() = ScheduleLogic.leagueTeamNames(ScheduleLogic.mergeUniqueMatches(allMatches, ownMatches))
|
||||
}
|
||||
|
||||
private fun List<ScheduleMatchDto>.withoutFriendly(): List<ScheduleMatchDto> = filterNot { it.isFriendly }
|
||||
|
||||
class ScheduleManager(
|
||||
private val clubTeamsApi: ClubTeamsApi,
|
||||
private val matchesApi: MatchesApi,
|
||||
@@ -155,8 +157,8 @@ class ScheduleManager(
|
||||
val leagueId = team.league?.id ?: return
|
||||
_state.update { it.copy(isLoading = true, error = null, viewMode = ScheduleViewMode.Team) }
|
||||
try {
|
||||
val own = matchesApi.listMatchesForLeague(clubId, leagueId, "own")
|
||||
val all = matchesApi.listMatchesForLeague(clubId, leagueId, "all")
|
||||
val own = matchesApi.listMatchesForLeague(clubId, leagueId, "own").withoutFriendly()
|
||||
val all = matchesApi.listMatchesForLeague(clubId, leagueId, "all").withoutFriendly()
|
||||
val table = runCatching { matchesApi.leagueTable(clubId, leagueId) }.getOrElse { emptyList() }
|
||||
_state.update {
|
||||
it.copy(
|
||||
@@ -198,7 +200,7 @@ class ScheduleManager(
|
||||
)
|
||||
}
|
||||
try {
|
||||
val matches = matchesApi.listMatchesForLeagues(clubId, _state.value.seasonId)
|
||||
val matches = matchesApi.listMatchesForLeagues(clubId, _state.value.seasonId).withoutFriendly()
|
||||
_state.update { it.copy(overallMatches = matches, isLoading = false, error = null) }
|
||||
} catch (t: Throwable) {
|
||||
_state.update {
|
||||
@@ -226,7 +228,7 @@ class ScheduleManager(
|
||||
)
|
||||
}
|
||||
try {
|
||||
val matches = matchesApi.listMatchesForLeagues(clubId, _state.value.seasonId)
|
||||
val matches = matchesApi.listMatchesForLeagues(clubId, _state.value.seasonId).withoutFriendly()
|
||||
_state.update { it.copy(overallMatches = matches, isLoading = false, error = null) }
|
||||
} catch (t: Throwable) {
|
||||
_state.update {
|
||||
@@ -299,6 +301,27 @@ class ScheduleManager(
|
||||
refresh(clubId)
|
||||
}
|
||||
|
||||
suspend fun updateMatchPlayersForMatch(
|
||||
clubId: Int,
|
||||
match: ScheduleMatchDto,
|
||||
ready: List<Int>,
|
||||
planned: List<Int>,
|
||||
played: List<Int>,
|
||||
) {
|
||||
val body = UpdateMatchPlayersBody(
|
||||
clubId = clubId,
|
||||
playersReady = ready,
|
||||
playersPlanned = planned,
|
||||
playersPlayed = played,
|
||||
)
|
||||
when {
|
||||
match.isFriendly && match.isSharedFriendly -> matchesApi.updateSharedFriendlyMatchPlayers(clubId, match.id, body)
|
||||
match.isFriendly -> matchesApi.updateFriendlyMatchPlayers(clubId, match.id, body)
|
||||
else -> matchesApi.updateMatchPlayers(match.id, body)
|
||||
}
|
||||
refresh(clubId)
|
||||
}
|
||||
|
||||
suspend fun createFriendlyMatch(clubId: Int, body: FriendlyMatchSaveBody) {
|
||||
val saved = matchesApi.createFriendlyMatch(clubId, body)
|
||||
_state.update { it.copy(friendlyMatches = ScheduleLogic.sortMatches(it.friendlyMatches + saved)) }
|
||||
|
||||
Reference in New Issue
Block a user