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

@ -3,29 +3,46 @@ package uca.iut.clermont.api
import retrofit2.http.GET import retrofit2.http.GET
import retrofit2.http.Headers import retrofit2.http.Headers
import retrofit2.http.Path 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.CompetitionResponse
import uca.iut.clermont.api.response.competitionResponse.CompetitionResult
import uca.iut.clermont.api.response.matchResponse.MatchResponse 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.Area
import uca.iut.clermont.model.PlayerResponse import uca.iut.clermont.model.PlayerResponse
interface FootballApi { 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") @GET("areas")
suspend fun getAreas(): List<Area> suspend fun getAreas(): AreaResponse
@Headers("X-Auth-Token: 7814ffe5b0314b5291a287d32a178e57") @Headers("X-Auth-Token: 7814ffe5b0314b5291a287d32a178e57")
@GET("persons/{id}") @GET("persons/{id}")
suspend fun getPlayer(@Path("id") playerId: Int): PlayerResponse 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") @Headers("X-Auth-Token: 7814ffe5b0314b5291a287d32a178e57")
@GET("competitions") @GET("competitions")
suspend fun getCompetitions(): CompetitionResponse 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") @Headers("X-Auth-Token: 7814ffe5b0314b5291a287d32a178e57")
@GET("matches") @GET("matches")
suspend fun getMatches(): MatchResponse 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() val matchList: MutableList<Match> = mutableListOf()
fun initMatches() { fun initMatches() {
@ -421,7 +421,7 @@ class StubData : DataManager() {
class StubAreaManager(private val parent: StubData) : AreaManager { 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) } parent.areaList.filter { it.name.contains(substring, ignoreCase = true) }
override suspend fun getItems(): List<Area> = parent.areaList override suspend fun getItems(): List<Area> = parent.areaList
@ -431,8 +431,6 @@ class StubData : DataManager() {
} }
class StubPeopleManager(private val parent: StubData) : PeopleManager { 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 override suspend fun getItems() = parent.peopleList
@ -440,11 +438,12 @@ class StubData : DataManager() {
} }
class StubMatchesManager(private val parent: StubData) : MatchesManager { 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) = override suspend fun getNbItemsByCompetition(id: Int) =
parent.matchList.filter { it.competition.name.contains(substring) } 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 override suspend fun getItems(): List<Match> = parent.matchList
@ -453,7 +452,7 @@ class StubData : DataManager() {
} }
class StubCompetitionsManager(private val parent: StubData) : CompetitionsManager { 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) } parent.competitionList.filter { it.name.contains(substring, ignoreCase = true) }
override suspend fun getItems() = parent.competitionList override suspend fun getItems() = parent.competitionList

@ -9,22 +9,20 @@ abstract class DataManager {
} }
interface AreaManager : GenericDataManager<Area> { interface AreaManager : GenericDataManager<Area> {
fun getItemsByName(substring: String): List<Area> suspend fun getItemsByName(substring: String): List<Area>
} }
interface PeopleManager : GenericDataManager<Personne> { interface PeopleManager : GenericDataManager<Personne> {}
fun getItemsByName(substring: String): List<Personne>
}
interface MatchesManager : GenericDataManager<Match> { 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> { interface CompetitionsManager : GenericDataManager<Competition> {
fun getItemsByName(substring: String): List<Competition> suspend fun getItemsByName(substring: String): List<Competition>
} }
interface TeamsManager : GenericDataManager<Team> { interface TeamsManager : GenericDataManager<Team> {

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