|
|
|
@ -10,8 +10,6 @@ import kotlinx.coroutines.coroutineScope
|
|
|
|
|
import retrofit2.Retrofit
|
|
|
|
|
import retrofit2.converter.gson.GsonConverterFactory
|
|
|
|
|
import uca.iut.clermont.model.*
|
|
|
|
|
import java.text.SimpleDateFormat
|
|
|
|
|
import java.util.*
|
|
|
|
|
|
|
|
|
|
val retrofit: Retrofit = Retrofit.Builder()
|
|
|
|
|
.baseUrl("https://api.football-data.org/v4/")
|
|
|
|
@ -29,29 +27,26 @@ class ApiManager : DataManager() {
|
|
|
|
|
|
|
|
|
|
class ApiAreaManager : AreaManager {
|
|
|
|
|
|
|
|
|
|
override fun getItemsByName(substring: String): List<Area> {
|
|
|
|
|
TODO("Not yet implemented")
|
|
|
|
|
override suspend fun getItemsByName(substring: String): List<Area> = coroutineScope {
|
|
|
|
|
val areas = footballApi.getAreas()
|
|
|
|
|
return@coroutineScope areas.areas.filter { it.name.contains(substring) }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override suspend fun getItems(): List<Area> {
|
|
|
|
|
TODO("Not yet implemented")
|
|
|
|
|
override suspend fun getItems(): List<Area> = coroutineScope {
|
|
|
|
|
val areas = footballApi.getAreas()
|
|
|
|
|
return@coroutineScope areas.areas
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override suspend fun getItemById(id: Int): Area? {
|
|
|
|
|
TODO("Not yet implemented")
|
|
|
|
|
override suspend fun getItemById(id: Int): Area = coroutineScope {
|
|
|
|
|
val area = footballApi.getArea(id)
|
|
|
|
|
return@coroutineScope area
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ApiPeopleManager : PeopleManager {
|
|
|
|
|
|
|
|
|
|
override fun getItemsByName(substring: String): List<Personne> {
|
|
|
|
|
TODO("Not yet implemented")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override suspend fun getItems(): List<Personne> {
|
|
|
|
|
TODO("Not yet implemented")
|
|
|
|
|
}
|
|
|
|
|
override suspend fun getItems(): List<Personne> = listOf()
|
|
|
|
|
|
|
|
|
|
override suspend fun getItemById(id: Int): Personne? = coroutineScope {
|
|
|
|
|
val personne = footballApi.getPlayer(id)
|
|
|
|
@ -63,42 +58,53 @@ class ApiManager : DataManager() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ApiMatchesManager : MatchesManager {
|
|
|
|
|
override fun getNbItemsByCompetition(substring: String): Int {
|
|
|
|
|
TODO("Not yet implemented")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun getItemsByCompetition(substring: String): List<Match> {
|
|
|
|
|
TODO("Not yet implemented")
|
|
|
|
|
override suspend fun getNbItemsByCompetition(id: Int): Int = coroutineScope {
|
|
|
|
|
val matches = footballApi.getMatchesByCompetition(id)
|
|
|
|
|
return@coroutineScope matches.matches.size
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override suspend fun getItemsByCompetition(id: Int): List<Match> =
|
|
|
|
|
coroutineScope {
|
|
|
|
|
val matches = footballApi.getMatches()
|
|
|
|
|
return@coroutineScope matches.matches.map { it.toModel() }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override suspend fun getItems(): List<Match> = coroutineScope {
|
|
|
|
|
val matches = footballApi.getMatches()
|
|
|
|
|
return@coroutineScope matches.matches.map { matchResult -> matchResult.toModel() }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override suspend fun getItemById(id: Int): Match? {
|
|
|
|
|
TODO("Not yet implemented")
|
|
|
|
|
override suspend fun getItemById(id: Int): Match = coroutineScope {
|
|
|
|
|
val match = footballApi.getMatch(id)
|
|
|
|
|
return@coroutineScope match.toModel()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ApiCompetitionsManager : CompetitionsManager {
|
|
|
|
|
override fun getItemsByName(substring: String): List<Competition> {
|
|
|
|
|
TODO("Not yet implemented")
|
|
|
|
|
|
|
|
|
|
override suspend fun getItemsByName(substring: String): List<Competition> = coroutineScope {
|
|
|
|
|
val competitons = footballApi.getCompetitions()
|
|
|
|
|
return@coroutineScope competitons.competitions.map { competitionResult -> competitionResult.toModel() }
|
|
|
|
|
.filter { it.name == substring }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override suspend fun getItems(): List<Competition> = coroutineScope {
|
|
|
|
|
val competitons = footballApi.getCompetitions()
|
|
|
|
|
return@coroutineScope competitons.competitions.map { competitionResult -> competitionResult.toModel() }.sortedBy { it.name }
|
|
|
|
|
return@coroutineScope competitons.competitions.map { competitionResult -> competitionResult.toModel() }
|
|
|
|
|
.sortedBy { it.name }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override suspend fun getItemById(id: Int): Competition? {
|
|
|
|
|
TODO("Not yet implemented")
|
|
|
|
|
override suspend fun getItemById(id: Int): Competition = coroutineScope {
|
|
|
|
|
val competition = footballApi.getCompetition(id)
|
|
|
|
|
return@coroutineScope competition.toModel()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ApiTeamsManager : TeamsManager {
|
|
|
|
|
|
|
|
|
|
override fun getItemsByName(substring: String): List<Team> {
|
|
|
|
|
TODO("Not yet implemented")
|
|
|
|
|
}
|
|
|
|
|