Realized function into the ApiManager
continuous-integration/drone/push Build is failing Details

pull/8/head
Emre KARTAL 2 years ago
parent a5ae9880ed
commit ea68bbecef

@ -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")
}

@ -3,29 +3,46 @@ package uca.iut.clermont.api
import retrofit2.http.GET
import retrofit2.http.Headers
import retrofit2.http.Path
import uca.iut.clermont.api.response.areaResponse.AreaResponse
import uca.iut.clermont.api.response.competitionResponse.CompetitionResponse
import uca.iut.clermont.api.response.competitionResponse.CompetitionResult
import uca.iut.clermont.api.response.matchResponse.MatchResponse
import uca.iut.clermont.api.response.matchResponse.MatchResult
import uca.iut.clermont.model.Area
import uca.iut.clermont.model.PlayerResponse
interface FootballApi {
@Headers("X-Auth-Token: 7814ffe5b0314b5291a287d32a178e57")
@GET("areas/{id}")
suspend fun getArea(@Path("id") id: Int): Area
@Headers("X-Auth-Token: 7814ffe5b0314b5291a287d32a178e57")
@GET("areas")
suspend fun getAreas(): List<Area>
suspend fun getAreas(): AreaResponse
@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("competitions/{id}")
suspend fun getCompetition(@Path("id") id: Int): CompetitionResult
@Headers("X-Auth-Token: 7814ffe5b0314b5291a287d32a178e57")
@GET("matches")
suspend fun getMatches(): MatchResponse
@Headers("X-Auth-Token: 7814ffe5b0314b5291a287d32a178e57")
@GET("matches/{id}")
suspend fun getMatch(@Path("id") id: Int): MatchResult
@Headers("X-Auth-Token: 7814ffe5b0314b5291a287d32a178e57")
@GET("matches/{id}/matches")
suspend fun getMatchesByCompetition(@Path("id") id: Int): MatchResponse
}

@ -0,0 +1,8 @@
package uca.iut.clermont.api.response.areaResponse
import uca.iut.clermont.model.Area
data class AreaResponse(
val areas: List<Area>,
val count: Int
)

@ -246,7 +246,7 @@ class StubData : DataManager() {
)
)
private val random = java.util.Random()
private val random = Random()
val matchList: MutableList<Match> = mutableListOf()
fun initMatches() {
@ -421,7 +421,7 @@ class StubData : DataManager() {
class StubAreaManager(private val parent: StubData) : AreaManager {
override fun getItemsByName(substring: String) =
override suspend fun getItemsByName(substring: String) =
parent.areaList.filter { it.name.contains(substring, ignoreCase = true) }
override suspend fun getItems(): List<Area> = parent.areaList
@ -431,8 +431,6 @@ class StubData : DataManager() {
}
class StubPeopleManager(private val parent: StubData) : PeopleManager {
override fun getItemsByName(substring: String) =
parent.peopleList.filter { it.name.contains(substring, ignoreCase = true) }
override suspend fun getItems() = parent.peopleList
@ -440,11 +438,12 @@ class StubData : DataManager() {
}
class StubMatchesManager(private val parent: StubData) : MatchesManager {
override fun getNbItemsByCompetition(substring: String) =
parent.matchList.filter { it.competition.name.contains(substring) }.count()
override fun getItemsByCompetition(substring: String) =
parent.matchList.filter { it.competition.name.contains(substring) }
override suspend fun getNbItemsByCompetition(id: Int) =
parent.matchList.filter { it.competition.id == id }.size
override suspend fun getItemsByCompetition(id: Int) =
parent.matchList.filter { it.competition.id == id }
override suspend fun getItems(): List<Match> = parent.matchList
@ -453,7 +452,7 @@ class StubData : DataManager() {
}
class StubCompetitionsManager(private val parent: StubData) : CompetitionsManager {
override fun getItemsByName(substring: String) =
override suspend fun getItemsByName(substring: String) =
parent.competitionList.filter { it.name.contains(substring, ignoreCase = true) }
override suspend fun getItems() = parent.competitionList

@ -9,22 +9,20 @@ abstract class DataManager {
}
interface AreaManager : GenericDataManager<Area> {
fun getItemsByName(substring: String): List<Area>
suspend fun getItemsByName(substring: String): List<Area>
}
interface PeopleManager : GenericDataManager<Personne> {
fun getItemsByName(substring: String): List<Personne>
}
interface PeopleManager : GenericDataManager<Personne> {}
interface MatchesManager : GenericDataManager<Match> {
fun getNbItemsByCompetition(substring: String): Int
suspend fun getNbItemsByCompetition(id: Int): Int
fun getItemsByCompetition(substring: String): List<Match>
suspend fun getItemsByCompetition(id: Int): List<Match>
}
interface CompetitionsManager : GenericDataManager<Competition> {
fun getItemsByName(substring: String): List<Competition>
suspend fun getItemsByName(substring: String): List<Competition>
}
interface TeamsManager : GenericDataManager<Team> {

@ -79,21 +79,21 @@ class DetailFragment : Fragment() {
dateStart.text = formattedDate
nbMatches.text =
/*nbMatches.text =
(activity as MainActivity).manager.matchesMgr.getNbItemsByCompetition(competition.name)
.toString()
.toString()*/
}
private fun initRecyclerView(view: View) {
val recyclerViewMatches = view.findViewById<RecyclerView>(R.id.listRecentsMatches)
/*val recyclerViewMatches = view.findViewById<RecyclerView>(R.id.listRecentsMatches)
with(recyclerViewMatches) {
layoutManager = LinearLayoutManager(view.context)
adapter = MatchesAdapter(
(activity as MainActivity).manager.matchesMgr.getItemsByCompetition(competition.name)
.toList().toTypedArray()
)
}
}*/
}
}
Loading…
Cancel
Save