Realized call API 📲
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
parent
6e3d94a354
commit
a5ae9880ed
@ -0,0 +1,31 @@
|
|||||||
|
package uca.iut.clermont.api
|
||||||
|
|
||||||
|
import retrofit2.http.GET
|
||||||
|
import retrofit2.http.Headers
|
||||||
|
import retrofit2.http.Path
|
||||||
|
import uca.iut.clermont.api.response.competitionResponse.CompetitionResponse
|
||||||
|
import uca.iut.clermont.api.response.matchResponse.MatchResponse
|
||||||
|
import uca.iut.clermont.model.Area
|
||||||
|
import uca.iut.clermont.model.PlayerResponse
|
||||||
|
|
||||||
|
interface FootballApi {
|
||||||
|
|
||||||
|
@GET("areas")
|
||||||
|
suspend fun getAreas(): List<Area>
|
||||||
|
|
||||||
|
@Headers("X-Auth-Token: 7814ffe5b0314b5291a287d32a178e57")
|
||||||
|
@GET("persons/{id}")
|
||||||
|
suspend fun getPlayer(@Path("id") playerId: Int): PlayerResponse
|
||||||
|
|
||||||
|
@Headers("X-Auth-Token: 7814ffe5b0314b5291a287d32a178e57")
|
||||||
|
@GET("persons")
|
||||||
|
suspend fun getPlayers(): List<PlayerResponse>
|
||||||
|
|
||||||
|
@Headers("X-Auth-Token: 7814ffe5b0314b5291a287d32a178e57")
|
||||||
|
@GET("competitions")
|
||||||
|
suspend fun getCompetitions(): CompetitionResponse
|
||||||
|
|
||||||
|
@Headers("X-Auth-Token: 7814ffe5b0314b5291a287d32a178e57")
|
||||||
|
@GET("matches")
|
||||||
|
suspend fun getMatches(): MatchResponse
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package uca.iut.clermont.api.response.competitionResponse
|
||||||
|
|
||||||
|
data class CompetitionResponse(
|
||||||
|
val competitions: List<CompetitionResult>,
|
||||||
|
val count: Int,
|
||||||
|
val filters: Filters
|
||||||
|
)
|
@ -0,0 +1,24 @@
|
|||||||
|
package uca.iut.clermont.api.response.competitionResponse
|
||||||
|
|
||||||
|
import uca.iut.clermont.model.Area
|
||||||
|
import uca.iut.clermont.model.Competition
|
||||||
|
|
||||||
|
class CompetitionResult(
|
||||||
|
val id: Int,
|
||||||
|
val name: String,
|
||||||
|
val code: String,
|
||||||
|
val type: String,
|
||||||
|
val emblem: String,
|
||||||
|
val currentSeason: CurrentSeason,
|
||||||
|
val area: Area
|
||||||
|
) {
|
||||||
|
fun toModel() = Competition(
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
code,
|
||||||
|
type,
|
||||||
|
emblem,
|
||||||
|
currentSeason.toModel(),
|
||||||
|
area
|
||||||
|
)
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package uca.iut.clermont.api.response.competitionResponse
|
||||||
|
|
||||||
|
import uca.iut.clermont.model.Season
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
data class CurrentSeason(
|
||||||
|
val currentMatchday: Int,
|
||||||
|
val endDate: String,
|
||||||
|
val id: Int,
|
||||||
|
val startDate: String,
|
||||||
|
val winner: Any
|
||||||
|
) {
|
||||||
|
fun toModel(): Season {
|
||||||
|
val calendar = Calendar.getInstance()
|
||||||
|
return Season(
|
||||||
|
id,
|
||||||
|
calendar.apply {
|
||||||
|
time = SimpleDateFormat("yyyy-MM-dd", Locale.US).parse(startDate)
|
||||||
|
},
|
||||||
|
calendar.apply {
|
||||||
|
time = SimpleDateFormat("yyyy-MM-dd", Locale.US).parse(endDate)
|
||||||
|
},
|
||||||
|
currentMatchday,
|
||||||
|
if (winner is Int) winner else null
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
package uca.iut.clermont.api.response.competitionResponse
|
||||||
|
|
||||||
|
data class Filters(
|
||||||
|
val client: String
|
||||||
|
)
|
@ -0,0 +1,7 @@
|
|||||||
|
package uca.iut.clermont.api.response.matchResponse
|
||||||
|
|
||||||
|
data class Filters(
|
||||||
|
val dateFrom: String,
|
||||||
|
val dateTo: String,
|
||||||
|
val permission: String
|
||||||
|
)
|
@ -0,0 +1,23 @@
|
|||||||
|
package uca.iut.clermont.api.response.matchResponse
|
||||||
|
|
||||||
|
import uca.iut.clermont.api.response.competitionResponse.CurrentSeason
|
||||||
|
import uca.iut.clermont.model.Area
|
||||||
|
import uca.iut.clermont.model.Competition
|
||||||
|
|
||||||
|
class MatchCompetitionResult(
|
||||||
|
val id: Int,
|
||||||
|
val name: String,
|
||||||
|
val code: String,
|
||||||
|
val type: String,
|
||||||
|
val emblem: String
|
||||||
|
) {
|
||||||
|
fun toModel(season: CurrentSeason, area: Area) = Competition(
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
code,
|
||||||
|
type,
|
||||||
|
emblem,
|
||||||
|
season.toModel(),
|
||||||
|
area
|
||||||
|
)
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package uca.iut.clermont.api.response.matchResponse
|
||||||
|
|
||||||
|
data class MatchResponse(
|
||||||
|
val filters: Filters,
|
||||||
|
val matches: List<MatchResult>,
|
||||||
|
val resultSet: ResultSet
|
||||||
|
)
|
@ -0,0 +1,32 @@
|
|||||||
|
package uca.iut.clermont.api.response.matchResponse
|
||||||
|
|
||||||
|
import uca.iut.clermont.api.response.competitionResponse.CurrentSeason
|
||||||
|
import uca.iut.clermont.model.Area
|
||||||
|
import uca.iut.clermont.model.Match
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
class MatchResult(
|
||||||
|
val id: Int,
|
||||||
|
val homeTeam: TeamResult,
|
||||||
|
val awayTeam: TeamResult,
|
||||||
|
val utcDate: String,
|
||||||
|
val status: String,
|
||||||
|
val score: ScoreResult,
|
||||||
|
val season: CurrentSeason,
|
||||||
|
val area: Area,
|
||||||
|
val competition: MatchCompetitionResult
|
||||||
|
) {
|
||||||
|
fun toModel() = Match(
|
||||||
|
id,
|
||||||
|
homeTeam.toModel(),
|
||||||
|
awayTeam.toModel(),
|
||||||
|
Calendar.getInstance().apply {
|
||||||
|
time = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US).parse(utcDate)
|
||||||
|
},
|
||||||
|
status,
|
||||||
|
score.toModel(),
|
||||||
|
competition.toModel(season, area)
|
||||||
|
|
||||||
|
)
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package uca.iut.clermont.api.response.matchResponse
|
||||||
|
|
||||||
|
data class ResultSet(
|
||||||
|
val competitions: String,
|
||||||
|
val count: Int,
|
||||||
|
val first: String,
|
||||||
|
val last: String,
|
||||||
|
val played: Int
|
||||||
|
)
|
@ -0,0 +1,16 @@
|
|||||||
|
package uca.iut.clermont.api.response.matchResponse
|
||||||
|
|
||||||
|
import uca.iut.clermont.model.Score
|
||||||
|
|
||||||
|
data class ScoreResult(
|
||||||
|
val duration: String,
|
||||||
|
val fullTime: Time,
|
||||||
|
val halfTime: Time,
|
||||||
|
val winner: String?
|
||||||
|
){
|
||||||
|
fun toModel() = Score(
|
||||||
|
fullTime.home,
|
||||||
|
fullTime.away,
|
||||||
|
winner
|
||||||
|
)
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
package uca.iut.clermont.api.response.matchResponse
|
||||||
|
|
||||||
|
import uca.iut.clermont.model.Area
|
||||||
|
import uca.iut.clermont.model.Coach
|
||||||
|
import uca.iut.clermont.model.Contract
|
||||||
|
import uca.iut.clermont.model.Team
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
class TeamResult(
|
||||||
|
val id: Int,
|
||||||
|
val name: String,
|
||||||
|
val shortName: String,
|
||||||
|
val crest: String
|
||||||
|
) {
|
||||||
|
fun toModel() = Team(
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
shortName,
|
||||||
|
crest,
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
Area(1, "", "", "", ""),
|
||||||
|
"",
|
||||||
|
Coach(
|
||||||
|
1, "", "", "", Calendar.getInstance()
|
||||||
|
.apply { set(2022, 12, 28) }, "",
|
||||||
|
Contract(
|
||||||
|
Calendar.getInstance().apply { set(2020, 7, 1) },
|
||||||
|
Calendar.getInstance().apply { set(2024, 7, 1) })
|
||||||
|
),
|
||||||
|
listOf(),
|
||||||
|
listOf()
|
||||||
|
|
||||||
|
)
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
package uca.iut.clermont.api.response.matchResponse
|
||||||
|
|
||||||
|
data class Time(
|
||||||
|
val away: Int?,
|
||||||
|
val home: Int?
|
||||||
|
)
|
@ -0,0 +1,6 @@
|
|||||||
|
package uca.iut.clermont.api.response.playerResponse
|
||||||
|
|
||||||
|
data class ContractResponse(
|
||||||
|
val start: String,
|
||||||
|
val until: String
|
||||||
|
)
|
@ -0,0 +1,7 @@
|
|||||||
|
package uca.iut.clermont.api.response.playerResponse
|
||||||
|
|
||||||
|
data class CurrentTeamResponse(
|
||||||
|
val id: Int,
|
||||||
|
val name: String,
|
||||||
|
val contract: ContractResponse
|
||||||
|
)
|
@ -0,0 +1,38 @@
|
|||||||
|
package uca.iut.clermont.model
|
||||||
|
|
||||||
|
import uca.iut.clermont.api.response.playerResponse.CurrentTeamResponse
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
data class PlayerResponse(
|
||||||
|
val id: Int,
|
||||||
|
val firstName: String,
|
||||||
|
val lastName: String,
|
||||||
|
val name: String,
|
||||||
|
val dateOfBirth: String,
|
||||||
|
val nationality: String,
|
||||||
|
val position: String,
|
||||||
|
val shirtNumber: Int,
|
||||||
|
val lastUpdated: String,
|
||||||
|
val currentTeam: CurrentTeamResponse
|
||||||
|
) {
|
||||||
|
fun toModel() = Personne(
|
||||||
|
id,
|
||||||
|
firstName,
|
||||||
|
lastName,
|
||||||
|
name,
|
||||||
|
Calendar.getInstance().apply {
|
||||||
|
time = SimpleDateFormat("yyyy-MM-dd", Locale.US).parse(dateOfBirth)
|
||||||
|
},
|
||||||
|
nationality,
|
||||||
|
Contract(
|
||||||
|
Calendar.getInstance().apply {
|
||||||
|
time = SimpleDateFormat("yyyy-MM", Locale.US).parse(currentTeam.contract.start)
|
||||||
|
},
|
||||||
|
Calendar.getInstance().apply {
|
||||||
|
time = SimpleDateFormat("yyyy-MM", Locale.US).parse(currentTeam.contract.until)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
package uca.iut.clermont.model
|
package uca.iut.clermont.model
|
||||||
|
|
||||||
interface GenericDataManager<T> {
|
interface GenericDataManager<T> {
|
||||||
fun getItems(): List<T>
|
suspend fun getItems(): List<T>
|
||||||
fun getItemById(id: Int): T?
|
suspend fun getItemById(id: Int): T?
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
package uca.iut.clermont.model
|
package uca.iut.clermont.model
|
||||||
|
|
||||||
class Score(
|
class Score(
|
||||||
val home: Int,
|
val home: Int?,
|
||||||
val away: Int,
|
val away: Int?,
|
||||||
val winner: String
|
val winner: String?
|
||||||
)
|
)
|
@ -1,13 +0,0 @@
|
|||||||
package uca.iut.clermont.view
|
|
||||||
|
|
||||||
import com.bumptech.glide.annotation.GlideModule
|
|
||||||
import com.bumptech.glide.module.AppGlideModule
|
|
||||||
|
|
||||||
@GlideModule
|
|
||||||
class SampleGlideModule : AppGlideModule() {
|
|
||||||
|
|
||||||
override fun isManifestParsingEnabled(): Boolean {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,4 @@
|
|||||||
|
package uca.iut.clermont.view.viewModel
|
||||||
|
|
||||||
|
class DetailViewModel {
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package uca.iut.clermont.view.viewModel
|
||||||
|
|
||||||
|
import androidx.lifecycle.MutableLiveData
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import uca.iut.clermont.api.ApiManager
|
||||||
|
import uca.iut.clermont.model.Competition
|
||||||
|
|
||||||
|
class FavoriteViewModel : ViewModel() {
|
||||||
|
|
||||||
|
val manager = ApiManager()
|
||||||
|
val competitions = MutableLiveData<List<Competition>>()
|
||||||
|
|
||||||
|
fun loadCompetitions() = viewModelScope.launch {
|
||||||
|
val result = manager.competitionsMgr.getItems()
|
||||||
|
competitions.value = result
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package uca.iut.clermont.view.viewModel
|
||||||
|
|
||||||
|
import androidx.lifecycle.MutableLiveData
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import uca.iut.clermont.api.ApiManager
|
||||||
|
import uca.iut.clermont.model.Match
|
||||||
|
|
||||||
|
class HomeViewModel : ViewModel() {
|
||||||
|
|
||||||
|
val manager = ApiManager()
|
||||||
|
val matches = MutableLiveData<List<Match>?>()
|
||||||
|
|
||||||
|
fun loadMatches() = viewModelScope.launch {
|
||||||
|
val matchResult = manager.matchesMgr.getItems()
|
||||||
|
matches.value = matchResult.filter { it.status == "FINISHED" }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue