Compare commits
12 Commits
master
...
ConnectAPI
Author | SHA1 | Date |
---|---|---|
|
6e24977f38 | 2 weeks ago |
|
5e99fa71f2 | 2 weeks ago |
|
5ba379ea9f | 2 weeks ago |
|
73eac61726 | 2 weeks ago |
|
694ccdab1e | 2 weeks ago |
![]() |
62e2376180 | 2 weeks ago |
|
5b3f1111d1 | 2 weeks ago |
|
72a2426dbd | 2 weeks ago |
|
6eec8158c8 | 2 weeks ago |
|
8362377241 | 2 weeks ago |
|
db175c17f9 | 2 weeks ago |
|
09be084651 | 2 weeks ago |
@ -1,6 +1,11 @@
|
|||||||
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,16 +1,37 @@
|
|||||||
package com.example.what_the_fantasy.data.model
|
package com.example.what_the_fantasy.data.model
|
||||||
|
|
||||||
import java.util.Date
|
import com.google.gson.annotations.SerializedName
|
||||||
|
|
||||||
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,
|
||||||
val type: SrcType,
|
|
||||||
val date: Int
|
@SerializedName("type")
|
||||||
|
val type: SrcType ,
|
||||||
|
|
||||||
|
@SerializedName("dateSource")
|
||||||
|
val date: Int,
|
||||||
|
|
||||||
|
@SerializedName("isValide")
|
||||||
|
val isValide : Boolean = true
|
||||||
|
|
||||||
)
|
)
|
@ -1,6 +1,31 @@
|
|||||||
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,11 +1,22 @@
|
|||||||
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
|
||||||
)
|
)
|
@ -0,0 +1,107 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
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,89 +1,302 @@
|
|||||||
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 {
|
|
||||||
// TODO("Not yet implemented")
|
override suspend fun validLogin(
|
||||||
// }
|
username: String,
|
||||||
//
|
passwd: String,
|
||||||
// override fun EditEmail(email: String, index : Int): Boolean {
|
navController: (Int) -> Unit,
|
||||||
// TODO("Not yet implemented")
|
initialierCurrentUser: (Int) -> Unit,
|
||||||
// }
|
currentUserViewModel: CurrentUserViewModel
|
||||||
//
|
): Boolean {
|
||||||
// override fun EditPasswd(passwd: String, index : Int) {
|
try {
|
||||||
// TODO("Not yet implemented")
|
val response = RetrofitInstance.api.getUserByUsername(username) // on récupère l'utilisateur
|
||||||
// }
|
val hashedPasswordAPI = response.password // récupère le mot de passe de l'api
|
||||||
//
|
val index =response.id
|
||||||
// override fun EditImage(imageURL: String, index : Int) {
|
//val hashPassWd = hashPassword(passwd)// hache mot de passe demandé
|
||||||
// TODO("Not yet implemented")
|
|
||||||
// }
|
if (passwd == hashedPasswordAPI) { // on compare les deux mots de passe
|
||||||
//
|
navController(index)
|
||||||
// override fun ChangeLangage(user: User) {
|
initialierCurrentUser(index)
|
||||||
// TODO("Not yet implemented")
|
currentUserViewModel.setUser(response)
|
||||||
// }
|
return true
|
||||||
//
|
}
|
||||||
// override fun AddFav(userId: Int, QuoteId: Int) {
|
else {
|
||||||
// TODO("Not yet implemented")
|
return false
|
||||||
// }
|
}
|
||||||
//
|
} catch (e: Exception) {
|
||||||
// override fun SupFav(userId: Int, QuoteId: Int) {
|
return false
|
||||||
// TODO("Not yet implemented")
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// override fun AddComment(content: String) {
|
override suspend fun EditUsername(username: String, index: Int, currentUserViewModel: CurrentUserViewModel): Boolean {
|
||||||
// TODO("Not yet implemented")
|
try {
|
||||||
// }
|
val userExistsResponse = RetrofitInstance.api.checkIfUsernameExists(username)
|
||||||
//
|
|
||||||
// override fun CreateUser(username: String, email: String, passwd: String, services: IServices) : Boolean {
|
Log.d("EditUsername", "Username check: $username exists = $userExistsResponse")
|
||||||
// TODO("Not yet implemented")
|
|
||||||
// }
|
if (userExistsResponse) {
|
||||||
//
|
Log.d("EditUsername", "Username $username already exists, cannot update.")
|
||||||
// override fun getFavorite(user: User): List<Quote> {
|
return false
|
||||||
// TODO("Not yet implemented")
|
}
|
||||||
// }
|
|
||||||
//
|
val responseUser = RetrofitInstance.api.getUserById(index)
|
||||||
// override fun SearchQuote(quote: String) {
|
|
||||||
// TODO("Not yet implemented")
|
val updatedUser = User(
|
||||||
// }
|
id = index,
|
||||||
//
|
username = username, // Nouveau nom d'utilisateur
|
||||||
// override fun getQuote(id: Int): Quote? {
|
email = responseUser.email,
|
||||||
// TODO("Not yet implemented")
|
password = responseUser.password,
|
||||||
// }
|
imgUrl = responseUser.imgUrl,
|
||||||
//
|
langage = responseUser.langage,
|
||||||
// override fun isFavorite(id: Int, user: User): Boolean {
|
date = responseUser.date
|
||||||
// TODO("Not yet implemented")
|
)
|
||||||
// }
|
|
||||||
//
|
val response = RetrofitInstance.api.updateUsername(index, updatedUser)
|
||||||
// override fun getAllFavorite(): List<Favorite> {
|
|
||||||
// TODO("Not yet implemented")
|
if (response.isSuccessful) {
|
||||||
// }
|
currentUserViewModel.setUser(updatedUser)
|
||||||
//
|
Log.d("EditUsername", "Username updated successfully.")
|
||||||
// override fun getAllQuote(): List<Quote> {
|
return true
|
||||||
// TODO("Not yet implemented")
|
} else {
|
||||||
// }
|
Log.d("EditUsername", "Failed to update username, API response not successful.")
|
||||||
//
|
return false
|
||||||
// override fun getSomeQuotes(nb: Int, page: Int): MutableList<Quote> {
|
}
|
||||||
// TODO("Not yet implemented")
|
} catch (e: Exception) {
|
||||||
// }
|
e.printStackTrace()
|
||||||
//
|
Log.d("EditUsername", "Exception occurred: ${e.message}")
|
||||||
// override fun getAllUsers(): List<User> {
|
return false
|
||||||
// TODO("Not yet implemented")
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// override fun getComment(quoteId: Int): List<Comment> {
|
|
||||||
// TODO("Not yet implemented")
|
override suspend fun EditEmail(email: String, index: Int,currentUserViewModel: CurrentUserViewModel): Boolean {
|
||||||
// }
|
try {
|
||||||
//
|
val userExistsResponse = RetrofitInstance.api.checkIfEmailExists(email)
|
||||||
// override fun getUserById(id: Int): User? {
|
|
||||||
// TODO("Not yet implemented")
|
if (userExistsResponse) {
|
||||||
// }
|
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