parent
ad5ae952ac
commit
09be084651
@ -0,0 +1,51 @@
|
|||||||
|
package com.example.what_the_fantasy.data.retrofit
|
||||||
|
|
||||||
|
import com.example.what_the_fantasy.data.model.SrcLanguage
|
||||||
|
import com.example.what_the_fantasy.data.model.User
|
||||||
|
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.Query
|
||||||
|
|
||||||
|
data class UserUpdateRequest(
|
||||||
|
val username: String,
|
||||||
|
val email: String,
|
||||||
|
val passwd: String,
|
||||||
|
val langage: SrcLanguage,
|
||||||
|
val imgUrl: String
|
||||||
|
)
|
||||||
|
|
||||||
|
interface UserApiService {
|
||||||
|
|
||||||
|
@GET("users/username")
|
||||||
|
suspend fun getUserByUsername(
|
||||||
|
@Query("username") username: String
|
||||||
|
): User
|
||||||
|
|
||||||
|
@GET("users/")
|
||||||
|
suspend fun getUserById(
|
||||||
|
@Query("id") id: Int
|
||||||
|
): User
|
||||||
|
|
||||||
|
@POST("users")
|
||||||
|
suspend fun updateUser(
|
||||||
|
@Query("id") id: Int,
|
||||||
|
@Body userUpdate: UserUpdateRequest
|
||||||
|
): Response<User>
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
object RetrofitInstance {
|
||||||
|
private const val BASE_URL = "https://codefirst.iut.uca.fr/containers/WhatTheFantasy-web-services/api/v1/"
|
||||||
|
|
||||||
|
val api: UserApiService by lazy {
|
||||||
|
Retrofit.Builder()
|
||||||
|
.baseUrl(BASE_URL)
|
||||||
|
.addConverterFactory(GsonConverterFactory.create())
|
||||||
|
.build()
|
||||||
|
.create(UserApiService::class.java)
|
||||||
|
}
|
||||||
|
}
|
@ -1,89 +1,162 @@
|
|||||||
package com.example.what_the_fantasy.data.services
|
package com.example.what_the_fantasy.data.services
|
||||||
|
|
||||||
|
import com.example.what_the_fantasy.data.local.UserStub.users
|
||||||
|
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.data.retrofit.UserUpdateRequest
|
||||||
|
|
||||||
//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
|
||||||
// }
|
): 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) {
|
return true
|
||||||
// TODO("Not yet implemented")
|
}
|
||||||
// }
|
else {
|
||||||
//
|
return false
|
||||||
// override fun AddFav(userId: Int, QuoteId: Int) {
|
}
|
||||||
// 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): Boolean {
|
||||||
//
|
try {
|
||||||
// override fun AddComment(content: String) {
|
val responseOldUser = RetrofitInstance.api.getUserById(index)
|
||||||
// TODO("Not yet implemented")
|
val request = UserUpdateRequest(username,
|
||||||
// }
|
responseOldUser.email,
|
||||||
//
|
responseOldUser.password,
|
||||||
// override fun CreateUser(username: String, email: String, passwd: String, services: IServices) : Boolean {
|
responseOldUser.langage,
|
||||||
// TODO("Not yet implemented")
|
responseOldUser.imgUrl)
|
||||||
// }
|
|
||||||
//
|
|
||||||
// override fun getFavorite(user: User): List<Quote> {
|
return false
|
||||||
// TODO("Not yet implemented")
|
}catch (e: Exception) {
|
||||||
// }
|
return false
|
||||||
//
|
}
|
||||||
// override fun SearchQuote(quote: String) {
|
}
|
||||||
// TODO("Not yet implemented")
|
|
||||||
// }
|
override suspend fun EditEmail(email: String, index: Int): Boolean {
|
||||||
//
|
try {
|
||||||
// override fun getQuote(id: Int): Quote? {
|
val responseOldUser = RetrofitInstance.api.getUserById(index)
|
||||||
// TODO("Not yet implemented")
|
val request = UserUpdateRequest(responseOldUser.username,
|
||||||
// }
|
email,
|
||||||
//
|
responseOldUser.password,
|
||||||
// override fun isFavorite(id: Int, user: User): Boolean {
|
responseOldUser.langage,
|
||||||
// TODO("Not yet implemented")
|
responseOldUser.imgUrl)
|
||||||
// }
|
|
||||||
//
|
|
||||||
// override fun getAllFavorite(): List<Favorite> {
|
return false
|
||||||
// TODO("Not yet implemented")
|
}catch (e: Exception) {
|
||||||
// }
|
return false
|
||||||
//
|
}
|
||||||
// override fun getAllQuote(): List<Quote> {
|
}
|
||||||
// TODO("Not yet implemented")
|
|
||||||
// }
|
|
||||||
//
|
override suspend fun EditPasswd(passwd: String, index: Int) {
|
||||||
// override fun getSomeQuotes(nb: Int, page: Int): MutableList<Quote> {
|
try {
|
||||||
// TODO("Not yet implemented")
|
val responseOldUser = RetrofitInstance.api.getUserById(index)
|
||||||
// }
|
val request = UserUpdateRequest(responseOldUser.username,
|
||||||
//
|
responseOldUser.email,
|
||||||
// override fun getAllUsers(): List<User> {
|
passwd,
|
||||||
// TODO("Not yet implemented")
|
responseOldUser.langage,
|
||||||
// }
|
responseOldUser.imgUrl)
|
||||||
//
|
|
||||||
// override fun getComment(quoteId: Int): List<Comment> {
|
}catch (_: Exception) { }
|
||||||
// TODO("Not yet implemented")
|
}
|
||||||
// }
|
|
||||||
//
|
override fun EditImage(index: Int): String {
|
||||||
// override fun getUserById(id: Int): User? {
|
TODO("Not yet implemented")
|
||||||
// TODO("Not yet implemented")
|
}
|
||||||
// }
|
|
||||||
//
|
override fun ChangeLangage(index: Int): SrcLanguage {
|
||||||
// override fun search(type : String ,search:String ,indexCount: Int): List<Quote>{
|
TODO("Not yet implemented")
|
||||||
// TODO("Not yet implemented")
|
}
|
||||||
// }
|
|
||||||
//}
|
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 fun CreateUser(username: String, email: String, passwd: String): Boolean {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
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 fun getSomeQuotes(nb: Int, page: Int): MutableList<Quote> {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun search(type: String, search: String, indexCount: Int): List<Quote> {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue