Compare commits
3 Commits
ConnectAPI
...
master
Author | SHA1 | Date |
---|---|---|
|
ec33ebbea4 | 2 weeks ago |
|
fba1f2b595 | 2 weeks ago |
|
fa6921bd72 | 2 weeks ago |
@ -1,11 +1,6 @@
|
|||||||
package com.example.what_the_fantasy.data.model
|
package com.example.what_the_fantasy.data.model
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName
|
|
||||||
|
|
||||||
data class Image(
|
data class Image(
|
||||||
@SerializedName("idImage")
|
|
||||||
val id: Int,
|
val id: Int,
|
||||||
|
|
||||||
@SerializedName("imagePath")
|
|
||||||
val url: String
|
val url: String
|
||||||
)
|
)
|
||||||
|
@ -1,37 +1,16 @@
|
|||||||
package com.example.what_the_fantasy.data.model
|
package com.example.what_the_fantasy.data.model
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName
|
import java.util.Date
|
||||||
|
|
||||||
data class Quote (
|
data class Quote (
|
||||||
|
|
||||||
@SerializedName("id")
|
|
||||||
val id: Int,
|
val id: Int,
|
||||||
|
|
||||||
@SerializedName("content")
|
|
||||||
val content: String,
|
val content: String,
|
||||||
|
|
||||||
@SerializedName("like")
|
|
||||||
var likes: Int,
|
var likes: Int,
|
||||||
|
|
||||||
@SerializedName("langage")
|
|
||||||
val language: SrcLanguage,
|
val language: SrcLanguage,
|
||||||
|
|
||||||
@SerializedName("character")
|
|
||||||
val character: String,
|
val character: String,
|
||||||
|
|
||||||
@SerializedName("titleSource")
|
|
||||||
val source: String,
|
val source: String,
|
||||||
|
|
||||||
@SerializedName("imagePath")
|
|
||||||
val imgUrl: String,
|
val imgUrl: String,
|
||||||
|
|
||||||
@SerializedName("type")
|
|
||||||
val type: SrcType,
|
val type: SrcType,
|
||||||
|
val date: Int
|
||||||
@SerializedName("dateSource")
|
|
||||||
val date: Int,
|
|
||||||
|
|
||||||
@SerializedName("isValide")
|
|
||||||
val isValide : Boolean = true
|
|
||||||
|
|
||||||
)
|
)
|
@ -1,31 +1,6 @@
|
|||||||
package com.example.what_the_fantasy.data.model
|
package com.example.what_the_fantasy.data.model
|
||||||
import com.google.gson.*
|
|
||||||
import java.lang.reflect.Type
|
|
||||||
|
|
||||||
enum class SrcLanguage(val code:Int) {
|
|
||||||
vf(1),
|
|
||||||
vo(0);
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
fun fromCode(code: Int): SrcLanguage? = values().find { it.code == code }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class LangAdapter : JsonSerializer<SrcLanguage>, JsonDeserializer<SrcLanguage> {
|
|
||||||
override fun serialize(
|
|
||||||
src: SrcLanguage?,
|
|
||||||
typeOfSrc: Type?,
|
|
||||||
context: JsonSerializationContext?
|
|
||||||
): JsonElement = JsonPrimitive(src?.code)
|
|
||||||
|
|
||||||
override fun deserialize(
|
|
||||||
json: JsonElement?,
|
|
||||||
typeOfT: Type?,
|
|
||||||
context: JsonDeserializationContext?
|
|
||||||
): SrcLanguage {
|
|
||||||
val code = json?.asInt
|
|
||||||
return SrcLanguage.fromCode(code ?: throw JsonParseException("Code null"))
|
|
||||||
?: throw JsonParseException("Unknown Status code: $code")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
enum class SrcLanguage {
|
||||||
|
vf,
|
||||||
|
vo
|
||||||
}
|
}
|
@ -1,22 +1,11 @@
|
|||||||
package com.example.what_the_fantasy.data.model
|
package com.example.what_the_fantasy.data.model
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName
|
|
||||||
|
|
||||||
class User(
|
class User(
|
||||||
@SerializedName("id")
|
|
||||||
val id:Int,
|
val id:Int,
|
||||||
@SerializedName("pseudo")
|
|
||||||
var username:String,
|
var username:String,
|
||||||
@SerializedName("email")
|
|
||||||
var email:String,
|
var email:String,
|
||||||
@SerializedName("date")
|
|
||||||
var date:String,
|
var date:String,
|
||||||
@SerializedName("imageProfil")
|
|
||||||
val imgUrl: String,
|
val imgUrl: String,
|
||||||
|
|
||||||
@SerializedName("password")
|
|
||||||
var password: String,
|
var password: String,
|
||||||
|
|
||||||
@SerializedName("lang")
|
|
||||||
var langage : SrcLanguage
|
var langage : SrcLanguage
|
||||||
)
|
)
|
@ -1,107 +0,0 @@
|
|||||||
package com.example.what_the_fantasy.data.retrofit
|
|
||||||
|
|
||||||
import com.example.what_the_fantasy.data.model.Image
|
|
||||||
import com.example.what_the_fantasy.data.model.LangAdapter
|
|
||||||
import com.example.what_the_fantasy.data.model.SrcTypeAdapter
|
|
||||||
import com.example.what_the_fantasy.data.model.Quote
|
|
||||||
import com.example.what_the_fantasy.data.model.SrcLanguage
|
|
||||||
import com.example.what_the_fantasy.data.model.SrcType
|
|
||||||
import com.example.what_the_fantasy.data.model.User
|
|
||||||
import com.example.what_the_fantasy.data.services.APIReponceList
|
|
||||||
import com.google.gson.Gson
|
|
||||||
import com.google.gson.GsonBuilder
|
|
||||||
import retrofit2.Response
|
|
||||||
import retrofit2.Retrofit
|
|
||||||
import retrofit2.converter.gson.GsonConverterFactory
|
|
||||||
import retrofit2.http.Body
|
|
||||||
import retrofit2.http.GET
|
|
||||||
import retrofit2.http.POST
|
|
||||||
import retrofit2.http.PUT
|
|
||||||
import retrofit2.http.Path
|
|
||||||
import retrofit2.http.Query
|
|
||||||
|
|
||||||
|
|
||||||
interface ApiService {
|
|
||||||
|
|
||||||
@GET("users/username")
|
|
||||||
suspend fun getUserByUsername(
|
|
||||||
@Query("username") username: String
|
|
||||||
): User
|
|
||||||
|
|
||||||
@GET("users/{id}")
|
|
||||||
suspend fun getUserById(
|
|
||||||
@Path("id") id: Int
|
|
||||||
): User
|
|
||||||
|
|
||||||
@GET("users/existusername")
|
|
||||||
suspend fun checkIfUsernameExists(
|
|
||||||
@Query("username") username: String
|
|
||||||
): Boolean
|
|
||||||
|
|
||||||
@GET("users/existemail")
|
|
||||||
suspend fun checkIfEmailExists(
|
|
||||||
@Query("email") email: String
|
|
||||||
): Boolean
|
|
||||||
|
|
||||||
|
|
||||||
@PUT("users")
|
|
||||||
suspend fun updateUsername(
|
|
||||||
@Query("id") id: Int,
|
|
||||||
@Body user: User // Envoie un objet `User` avec les nouvelles données
|
|
||||||
): Response<Unit>
|
|
||||||
|
|
||||||
@POST("users")
|
|
||||||
suspend fun addUser(
|
|
||||||
@Body newUser: User
|
|
||||||
): Response<Unit>
|
|
||||||
|
|
||||||
|
|
||||||
@GET("quote/dailyquote")
|
|
||||||
suspend fun getDailyQuote(
|
|
||||||
@Query("year") year: Int,
|
|
||||||
@Query("month") month: Int,
|
|
||||||
@Query("day") day: Int,
|
|
||||||
@Query("lang") lang: SrcLanguage
|
|
||||||
): Quote
|
|
||||||
|
|
||||||
@GET("quote/{id}")
|
|
||||||
suspend fun getQuoteById(
|
|
||||||
@Path("id")id : Int
|
|
||||||
):Quote
|
|
||||||
|
|
||||||
@GET("quote/all")
|
|
||||||
suspend fun getAllQuote(
|
|
||||||
@Query("index") index: Int,
|
|
||||||
@Query("count") count: Int
|
|
||||||
): APIReponceList<Quote>
|
|
||||||
|
|
||||||
|
|
||||||
@GET("image/all")
|
|
||||||
suspend fun getAllImages(
|
|
||||||
@Query("index") index: Int,
|
|
||||||
@Query("count") count: Int
|
|
||||||
): List<Image>
|
|
||||||
|
|
||||||
@GET("image/{id}")
|
|
||||||
suspend fun getImageById(
|
|
||||||
@Path("id") id: Int
|
|
||||||
): Image
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
object RetrofitInstance {
|
|
||||||
private const val BASE_URL = "https://codefirst.iut.uca.fr/containers/WhatTheFantasy-web-services/api/v1/"
|
|
||||||
|
|
||||||
private val gson: Gson = GsonBuilder()
|
|
||||||
.registerTypeAdapter(SrcLanguage::class.java, LangAdapter())
|
|
||||||
.registerTypeAdapter(SrcType::class.java, SrcTypeAdapter())
|
|
||||||
.create()
|
|
||||||
|
|
||||||
val api: ApiService by lazy {
|
|
||||||
Retrofit.Builder()
|
|
||||||
.baseUrl(BASE_URL)
|
|
||||||
.addConverterFactory(GsonConverterFactory.create(gson))
|
|
||||||
.build()
|
|
||||||
.create(ApiService::class.java)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
package com.example.what_the_fantasy.data.services
|
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName
|
|
||||||
|
|
||||||
data class APIReponceList<T> (
|
|
||||||
@SerializedName("totalCount")
|
|
||||||
val totalCount: Int,
|
|
||||||
|
|
||||||
@SerializedName("pageIndex")
|
|
||||||
val index: Int,
|
|
||||||
|
|
||||||
@SerializedName("countPerPage")
|
|
||||||
val count: Int,
|
|
||||||
|
|
||||||
@SerializedName("items")
|
|
||||||
val items: MutableList<T>,
|
|
||||||
)
|
|
@ -1,302 +1,89 @@
|
|||||||
package com.example.what_the_fantasy.data.services
|
package com.example.what_the_fantasy.data.services
|
||||||
|
|
||||||
import android.os.Build
|
|
||||||
import android.util.Log
|
|
||||||
import androidx.annotation.RequiresApi
|
|
||||||
import com.example.what_the_fantasy.data.local.ImageStub.allImages
|
|
||||||
import com.example.what_the_fantasy.data.model.Comment
|
|
||||||
import com.example.what_the_fantasy.data.model.Favorite
|
|
||||||
import com.example.what_the_fantasy.data.model.Quote
|
|
||||||
import com.example.what_the_fantasy.data.model.SrcLanguage
|
|
||||||
import com.example.what_the_fantasy.data.model.User
|
|
||||||
import com.example.what_the_fantasy.data.retrofit.RetrofitInstance
|
|
||||||
import com.example.what_the_fantasy.ui.viewModels.CurrentUserViewModel
|
|
||||||
import java.time.LocalDate
|
|
||||||
import java.util.Calendar
|
|
||||||
import java.util.Date
|
|
||||||
|
|
||||||
//import com.example.what_the_fantasy.data.model.Comment
|
//import com.example.what_the_fantasy.data.model.Comment
|
||||||
//import com.example.what_the_fantasy.data.model.Favorite
|
//import com.example.what_the_fantasy.data.model.Favorite
|
||||||
//import com.example.what_the_fantasy.data.model.Quote
|
//import com.example.what_the_fantasy.data.model.Quote
|
||||||
//import com.example.what_the_fantasy.data.model.User
|
//import com.example.what_the_fantasy.data.model.User
|
||||||
////import com.example.what_the_fantasy.ui.navigations.Destination
|
////import com.example.what_the_fantasy.ui.navigations.Destination
|
||||||
|
|
||||||
class ServicesAPI : IServices {
|
//class ServicesAPI : IServices {
|
||||||
|
// override fun EditUsername(username: String, index : Int): Boolean {
|
||||||
override suspend fun validLogin(
|
// TODO("Not yet implemented")
|
||||||
username: String,
|
// }
|
||||||
passwd: String,
|
//
|
||||||
navController: (Int) -> Unit,
|
// override fun EditEmail(email: String, index : Int): Boolean {
|
||||||
initialierCurrentUser: (Int) -> Unit,
|
// TODO("Not yet implemented")
|
||||||
currentUserViewModel: CurrentUserViewModel
|
// }
|
||||||
): Boolean {
|
//
|
||||||
try {
|
// override fun EditPasswd(passwd: String, index : Int) {
|
||||||
val response = RetrofitInstance.api.getUserByUsername(username) // on récupère l'utilisateur
|
// TODO("Not yet implemented")
|
||||||
val hashedPasswordAPI = response.password // récupère le mot de passe de l'api
|
// }
|
||||||
val index =response.id
|
//
|
||||||
//val hashPassWd = hashPassword(passwd)// hache mot de passe demandé
|
// override fun EditImage(imageURL: String, index : Int) {
|
||||||
|
// TODO("Not yet implemented")
|
||||||
if (passwd == hashedPasswordAPI) { // on compare les deux mots de passe
|
// }
|
||||||
navController(index)
|
//
|
||||||
initialierCurrentUser(index)
|
// override fun ChangeLangage(user: User) {
|
||||||
currentUserViewModel.setUser(response)
|
// TODO("Not yet implemented")
|
||||||
return true
|
// }
|
||||||
}
|
//
|
||||||
else {
|
// override fun AddFav(userId: Int, QuoteId: Int) {
|
||||||
return false
|
// TODO("Not yet implemented")
|
||||||
}
|
// }
|
||||||
} catch (e: Exception) {
|
//
|
||||||
return false
|
// override fun SupFav(userId: Int, QuoteId: Int) {
|
||||||
}
|
// TODO("Not yet implemented")
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
override suspend fun EditUsername(username: String, index: Int, currentUserViewModel: CurrentUserViewModel): Boolean {
|
// override fun AddComment(content: String) {
|
||||||
try {
|
// TODO("Not yet implemented")
|
||||||
val userExistsResponse = RetrofitInstance.api.checkIfUsernameExists(username)
|
// }
|
||||||
|
//
|
||||||
Log.d("EditUsername", "Username check: $username exists = $userExistsResponse")
|
// override fun CreateUser(username: String, email: String, passwd: String, services: IServices) : Boolean {
|
||||||
|
// TODO("Not yet implemented")
|
||||||
if (userExistsResponse) {
|
// }
|
||||||
Log.d("EditUsername", "Username $username already exists, cannot update.")
|
//
|
||||||
return false
|
// override fun getFavorite(user: User): List<Quote> {
|
||||||
}
|
// TODO("Not yet implemented")
|
||||||
|
// }
|
||||||
val responseUser = RetrofitInstance.api.getUserById(index)
|
//
|
||||||
|
// override fun SearchQuote(quote: String) {
|
||||||
val updatedUser = User(
|
// TODO("Not yet implemented")
|
||||||
id = index,
|
// }
|
||||||
username = username, // Nouveau nom d'utilisateur
|
//
|
||||||
email = responseUser.email,
|
// override fun getQuote(id: Int): Quote? {
|
||||||
password = responseUser.password,
|
// TODO("Not yet implemented")
|
||||||
imgUrl = responseUser.imgUrl,
|
// }
|
||||||
langage = responseUser.langage,
|
//
|
||||||
date = responseUser.date
|
// override fun isFavorite(id: Int, user: User): Boolean {
|
||||||
)
|
// TODO("Not yet implemented")
|
||||||
|
// }
|
||||||
val response = RetrofitInstance.api.updateUsername(index, updatedUser)
|
//
|
||||||
|
// override fun getAllFavorite(): List<Favorite> {
|
||||||
if (response.isSuccessful) {
|
// TODO("Not yet implemented")
|
||||||
currentUserViewModel.setUser(updatedUser)
|
// }
|
||||||
Log.d("EditUsername", "Username updated successfully.")
|
//
|
||||||
return true
|
// override fun getAllQuote(): List<Quote> {
|
||||||
} else {
|
// TODO("Not yet implemented")
|
||||||
Log.d("EditUsername", "Failed to update username, API response not successful.")
|
// }
|
||||||
return false
|
//
|
||||||
}
|
// override fun getSomeQuotes(nb: Int, page: Int): MutableList<Quote> {
|
||||||
} catch (e: Exception) {
|
// TODO("Not yet implemented")
|
||||||
e.printStackTrace()
|
// }
|
||||||
Log.d("EditUsername", "Exception occurred: ${e.message}")
|
//
|
||||||
return false
|
// override fun getAllUsers(): List<User> {
|
||||||
}
|
// TODO("Not yet implemented")
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
// override fun getComment(quoteId: Int): List<Comment> {
|
||||||
override suspend fun EditEmail(email: String, index: Int,currentUserViewModel: CurrentUserViewModel): Boolean {
|
// TODO("Not yet implemented")
|
||||||
try {
|
// }
|
||||||
val userExistsResponse = RetrofitInstance.api.checkIfEmailExists(email)
|
//
|
||||||
|
// override fun getUserById(id: Int): User? {
|
||||||
if (userExistsResponse) {
|
// TODO("Not yet implemented")
|
||||||
Log.d("EditEmail", "Exception occurred: The email alredy exist")
|
// }
|
||||||
return false
|
//
|
||||||
}
|
// override fun search(type : String ,search:String ,indexCount: Int): List<Quote>{
|
||||||
|
// TODO("Not yet implemented")
|
||||||
val responseUser = RetrofitInstance.api.getUserById(index)
|
// }
|
||||||
|
//}
|
||||||
val updatedUser = User(
|
|
||||||
id = index,
|
|
||||||
username = responseUser.username,
|
|
||||||
email = email,// Nouvel email d'utilisateur
|
|
||||||
password = responseUser.password,
|
|
||||||
imgUrl = responseUser.imgUrl,
|
|
||||||
langage = responseUser.langage,
|
|
||||||
date = responseUser.date
|
|
||||||
)
|
|
||||||
|
|
||||||
val response = RetrofitInstance.api.updateUsername(index, updatedUser)
|
|
||||||
|
|
||||||
if (response.isSuccessful) {
|
|
||||||
currentUserViewModel.setUser(updatedUser)
|
|
||||||
return true
|
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
e.printStackTrace()
|
|
||||||
Log.d("EditEmail", "Exception occurred: ${e.message}")
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun EditPasswd(passwd: String, index: Int, currentUserViewModel: CurrentUserViewModel): Boolean {
|
|
||||||
try {
|
|
||||||
val responseUser = RetrofitInstance.api.getUserById(index)
|
|
||||||
|
|
||||||
val updatedUser = User(
|
|
||||||
id = index,
|
|
||||||
username = responseUser.username,
|
|
||||||
email = responseUser.username,
|
|
||||||
password = passwd,
|
|
||||||
//password = hashPassword(passwd),
|
|
||||||
imgUrl = responseUser.imgUrl,
|
|
||||||
langage = responseUser.langage,
|
|
||||||
date = responseUser.date
|
|
||||||
)
|
|
||||||
|
|
||||||
val response = RetrofitInstance.api.updateUsername(index, updatedUser)
|
|
||||||
|
|
||||||
if (response.isSuccessful) {
|
|
||||||
currentUserViewModel.setUser(updatedUser)
|
|
||||||
return true
|
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
e.printStackTrace()
|
|
||||||
Log.d("EditPasswd", "Exception occurred: ${e.message}")
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun EditImage(index: Int, currentUserViewModel : CurrentUserViewModel): String {
|
|
||||||
try {
|
|
||||||
|
|
||||||
val responseUser = RetrofitInstance.api.getUserById(index)
|
|
||||||
|
|
||||||
val updatedUser = User(
|
|
||||||
id = index,
|
|
||||||
username = responseUser.username,
|
|
||||||
email = responseUser.email,// Nouvel email d'utilisateur
|
|
||||||
password = responseUser.password,
|
|
||||||
imgUrl = randomImage(),
|
|
||||||
langage = responseUser.langage,
|
|
||||||
date = responseUser.date
|
|
||||||
)
|
|
||||||
|
|
||||||
val response = RetrofitInstance.api.updateUsername(index, updatedUser)
|
|
||||||
|
|
||||||
if (response.isSuccessful) {
|
|
||||||
currentUserViewModel.setUser(updatedUser)
|
|
||||||
return updatedUser.imgUrl
|
|
||||||
} else {
|
|
||||||
return responseUser.imgUrl
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
e.printStackTrace()
|
|
||||||
return ""
|
|
||||||
Log.d("EditEmail", "Exception occurred: ${e.message}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
override suspend fun ChangeLangage(index: Int, currentUserViewModel : CurrentUserViewModel): SrcLanguage {
|
|
||||||
val responseUser = RetrofitInstance.api.getUserById(index)
|
|
||||||
var langage : SrcLanguage
|
|
||||||
|
|
||||||
if(responseUser.langage == SrcLanguage.vf){
|
|
||||||
langage = SrcLanguage.vo
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
langage = SrcLanguage.vf
|
|
||||||
}
|
|
||||||
|
|
||||||
val updatedUser = User(
|
|
||||||
id = index,
|
|
||||||
username = responseUser.username,
|
|
||||||
email = responseUser.email,
|
|
||||||
password = responseUser.password,
|
|
||||||
imgUrl = responseUser.imgUrl,
|
|
||||||
langage = langage,
|
|
||||||
date = responseUser.date
|
|
||||||
)
|
|
||||||
RetrofitInstance.api.updateUsername(index, updatedUser)
|
|
||||||
currentUserViewModel.setUser(updatedUser)
|
|
||||||
return langage
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun isUsernameExist(username: String): Boolean {
|
|
||||||
TODO("Not yet implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun isEmailExist(email: String): Boolean {
|
|
||||||
TODO("Not yet implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun AddFav(userId: Int, QuoteId: Int) {
|
|
||||||
TODO("Not yet implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun SupFav(userId: Int, QuoteId: Int) {
|
|
||||||
TODO("Not yet implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun AddComment(content: String) {
|
|
||||||
TODO("Not yet implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
override suspend fun CreateUser(username: String, email: String, passwd: String): Boolean {
|
|
||||||
val today = Calendar.getInstance().time
|
|
||||||
val rep =RetrofitInstance.api.addUser( User(15,username,email,today.toString(),"img",passwd,SrcLanguage.vo))
|
|
||||||
Log.d("test",rep.toString())
|
|
||||||
if(rep.code() in 200..299) return true
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getFavorite(user: User): List<Quote> {
|
|
||||||
TODO("Not yet implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getAllUsers(): List<User> {
|
|
||||||
TODO("Not yet implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getComment(quoteId: Int): List<Comment> {
|
|
||||||
TODO("Not yet implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getUserById(id: Int): User {
|
|
||||||
return RetrofitInstance.api.getUserById(id)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getQuote(id: Int): Quote? {
|
|
||||||
TODO("Not yet implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun isFavorite(idQuote: Int, iduser: Int): Boolean {
|
|
||||||
TODO("Not yet implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getAllFavorite(): List<Favorite> {
|
|
||||||
TODO("Not yet implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getAllQuote(): List<Quote> {
|
|
||||||
TODO("Not yet implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getSomeQuotes(nb: Int, page: Int): MutableList<Quote> {
|
|
||||||
val result = RetrofitInstance.api.getAllQuote(page,nb)
|
|
||||||
return result.items
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.O)
|
|
||||||
override suspend fun getDalyQuote(langage : SrcLanguage): Quote {
|
|
||||||
val today = LocalDate.now()
|
|
||||||
return RetrofitInstance.api.getDailyQuote(today.year, today.monthValue, today.dayOfMonth, langage)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun search(type: String, search: String, indexCount: Int): List<Quote> {
|
|
||||||
TODO("Not yet implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------
|
|
||||||
suspend fun randomImage() : String{
|
|
||||||
val imagesList = RetrofitInstance.api.getAllImages(0, 300)
|
|
||||||
val sizeList = imagesList.size
|
|
||||||
return RetrofitInstance.api.getImageById((0..sizeList).random()).url
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in new issue