parent
15a6829ee8
commit
0d022846c0
@ -1,32 +0,0 @@
|
|||||||
package fr.iut.sciencequest.model.buisness.Scientifique
|
|
||||||
|
|
||||||
import android.util.Log
|
|
||||||
import fr.iut.sciencequest.model.buisness.createRequestService
|
|
||||||
import fr.iut.sciencequest.model.dto.ScientifiqueDTOs.ScientifiqueDTO
|
|
||||||
import fr.iut.sciencequest.model.dto.ScientifiqueDTOs.ScientifiqueListDTO
|
|
||||||
import kotlinx.coroutines.flow.flow
|
|
||||||
import retrofit2.Call
|
|
||||||
import retrofit2.Callback
|
|
||||||
import retrofit2.Response
|
|
||||||
import retrofit2.create
|
|
||||||
import java.lang.IllegalArgumentException
|
|
||||||
|
|
||||||
suspend fun fetchScientifiqueById(id: Int) = flow {
|
|
||||||
val serviceClient = createRequestService().create<ScientifiqueRequestService>()
|
|
||||||
try {
|
|
||||||
val response = serviceClient.getScientifique(id)
|
|
||||||
emit(response)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.e("Requete API",e.message.toString())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun fetchScientifiques(index: Int) = flow {
|
|
||||||
val serviceClient = createRequestService().create<ScientifiqueRequestService>()
|
|
||||||
try {
|
|
||||||
val response = serviceClient.getScientifiques(index)
|
|
||||||
emit(response)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.e("Requete API",e.message.toString())
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,9 @@
|
|||||||
|
package fr.iut.sciencequest.model.repositories.scientifique
|
||||||
|
|
||||||
|
import fr.iut.sciencequest.model.metier.Scientifique
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
|
interface IScientifiqueRepository {
|
||||||
|
suspend fun fetchScientifiques(index: Int): Flow<List<Scientifique>>
|
||||||
|
suspend fun fetchScientifiqueById(id: Int): Flow<Scientifique>
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package fr.iut.sciencequest.model.repositories.scientifique
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
|
import fr.iut.sciencequest.model.buisness.Scientifique.ScientifiqueRequestService
|
||||||
|
import fr.iut.sciencequest.model.buisness.createRequestService
|
||||||
|
import fr.iut.sciencequest.model.dto.extensions.ToModel
|
||||||
|
import fr.iut.sciencequest.model.metier.Scientifique
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.flow
|
||||||
|
import retrofit2.create
|
||||||
|
|
||||||
|
class ScientifqueAPIRepository: IScientifiqueRepository {
|
||||||
|
suspend override fun fetchScientifiqueById(id: Int): Flow<Scientifique> = flow {
|
||||||
|
val serviceClient = createRequestService().create<ScientifiqueRequestService>()
|
||||||
|
try {
|
||||||
|
val response = serviceClient.getScientifique(id)
|
||||||
|
emit(response.ToModel())
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("Requete API",e.message.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend override fun fetchScientifiques(index: Int): Flow<List<Scientifique>> = flow {
|
||||||
|
val serviceClient = createRequestService().create<ScientifiqueRequestService>()
|
||||||
|
try {
|
||||||
|
val response = serviceClient.getScientifiques(index)
|
||||||
|
emit(response.scientifiques.ToModel())
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("Requete API",e.message.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue