debut api acceuil mais recupere pas de donné

ConnectAPI
Kentin BRONGNIART 3 months ago
parent 694ccdab1e
commit 73eac61726

@ -5,6 +5,7 @@ import com.example.what_the_fantasy.data.model.LangAdapter
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.SrcLanguage 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.model.User
import com.example.what_the_fantasy.data.services.APIReponceList
import com.google.gson.Gson import com.google.gson.Gson
import com.google.gson.GsonBuilder import com.google.gson.GsonBuilder
import retrofit2.Response import retrofit2.Response
@ -61,7 +62,10 @@ interface ApiService {
@GET("quote/{id}") @GET("quote/{id}")
suspend fun getQuoteById(@Path("id")id : Int):Quote suspend fun getQuoteById(@Path("id")id : Int):Quote
@GET("quote/all") @GET("quote/all")
suspend fun getAllQuote( @Query("index") index: Int, @Query("count") count: Int):List<Quote> suspend fun getAllQuote(
@Query("index") index: Int,
@Query("count") count: Int
): APIReponceList<Quote>
@GET("image/all") @GET("image/all")

@ -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")
var index: Int,
@SerializedName("countPerPage")
var count: Int,
@SerializedName("items")
var items: MutableList<T>,
)

@ -40,7 +40,7 @@ interface IServices {
suspend fun isFavorite(idQuote : Int, iduser: Int): Boolean suspend fun isFavorite(idQuote : Int, iduser: Int): Boolean
fun getAllFavorite(): List<Favorite> fun getAllFavorite(): List<Favorite>
fun getAllQuote(): List<Quote> fun getAllQuote(): List<Quote>
fun getSomeQuotes(nb: Int, page: Int) : MutableList<Quote> suspend fun getSomeQuotes(nb: Int, page: Int) : MutableList<Quote>
suspend fun getDalyQuote(langage : SrcLanguage) : Quote suspend fun getDalyQuote(langage : SrcLanguage) : Quote
fun search(type : String ,search:String ,indexCount: Int): List<Quote> fun search(type : String ,search:String ,indexCount: Int): List<Quote>
} }

@ -270,8 +270,9 @@ class ServicesAPI : IServices {
TODO("Not yet implemented") TODO("Not yet implemented")
} }
override fun getSomeQuotes(nb: Int, page: Int): MutableList<Quote> { override suspend fun getSomeQuotes(nb: Int, page: Int): MutableList<Quote> {
TODO("Not yet implemented") val reponce = RetrofitInstance.api.getAllQuote(page,nb)
return reponce.items
} }
@RequiresApi(Build.VERSION_CODES.O) @RequiresApi(Build.VERSION_CODES.O)

@ -143,7 +143,7 @@ class ServicesStub : IServices {
return (quotes.find { it.id == id }) return (quotes.find { it.id == id })
} }
override fun getSomeQuotes(nb: Int, page: Int): MutableList<Quote> { override suspend fun getSomeQuotes(nb: Int, page: Int): MutableList<Quote> {
var nbQuote = nb var nbQuote = nb
if(nb < 0) nbQuote = 1 if(nb < 0) nbQuote = 1

@ -16,6 +16,7 @@ import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController import androidx.navigation.compose.rememberNavController
import androidx.navigation.toRoute import androidx.navigation.toRoute
import com.example.what_the_fantasy.data.services.ServicesAPI
import com.example.what_the_fantasy.data.services.ServicesStub import com.example.what_the_fantasy.data.services.ServicesStub
import com.example.what_the_fantasy.ui.screens.* import com.example.what_the_fantasy.ui.screens.*
import com.example.what_the_fantasy.ui.viewModels.AuthUserViewModel import com.example.what_the_fantasy.ui.viewModels.AuthUserViewModel
@ -73,7 +74,8 @@ data class RecapSubmit(val userIndex: Int,
@Composable @Composable
fun AppNavigator() { fun AppNavigator() {
val navController = rememberNavController() val navController = rememberNavController()
val services = ServicesStub() val servicesStub = ServicesStub()
val services = ServicesAPI()
//ViewModel pour l'authentification //ViewModel pour l'authentification
val authUserVM : AuthUserViewModel = viewModel() val authUserVM : AuthUserViewModel = viewModel()
@ -157,7 +159,7 @@ fun AppNavigator() {
) )
}, },
navSearch = { navController.navigate(Search(currentUserState.id))}, navSearch = { navController.navigate(Search(currentUserState.id))},
services = services, services = servicesStub,
currentUserVM = currentUserVM, currentUserVM = currentUserVM,
currentUserState = currentUserState, currentUserState = currentUserState,
) )
@ -187,7 +189,7 @@ fun AppNavigator() {
navQuiz = { navController.navigate(QuizMenu(currentUserState.id)) }, navQuiz = { navController.navigate(QuizMenu(currentUserState.id)) },
navProfil = { navController.navigate(Profil(currentUserState.id)) }, navProfil = { navController.navigate(Profil(currentUserState.id)) },
navFavorite = { navController.navigate(Favorite(currentUserState.id)) }, navFavorite = { navController.navigate(Favorite(currentUserState.id)) },
service = services, service = servicesStub,
currentUserVM = currentUserVM, currentUserVM = currentUserVM,
currentUserState = currentUserState, currentUserState = currentUserState,
navSearch = { navController.navigate(Search(currentUserState.id))}, navSearch = { navController.navigate(Search(currentUserState.id))},

@ -1,6 +1,7 @@
package com.example.what_the_fantasy.ui.screens package com.example.what_the_fantasy.ui.screens
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.util.Log
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
@ -20,6 +21,8 @@ import androidx.compose.ui.unit.sp
import com.example.what_the_fantasy.R import com.example.what_the_fantasy.R
import com.example.what_the_fantasy.data.local.DailyQuoteStub import com.example.what_the_fantasy.data.local.DailyQuoteStub
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.SrcLanguage
import com.example.what_the_fantasy.data.model.SrcType
import com.example.what_the_fantasy.data.services.IServices import com.example.what_the_fantasy.data.services.IServices
import com.example.what_the_fantasy.ui.components.NavBar import com.example.what_the_fantasy.ui.components.NavBar
import com.example.what_the_fantasy.ui.components.QuoteLittle import com.example.what_the_fantasy.ui.components.QuoteLittle
@ -43,9 +46,12 @@ fun AccueilPage(
) { ) {
//val dailyQuote = services.getDalyQuote(currentUserState.langage) val coroutineScope = rememberCoroutineScope()
val dailyQuote = Quote(-1,"",0,SrcLanguage.vo,"","","",SrcType.Movie,0)
val dailyQuote = DailyQuoteStub.dailyQuote coroutineScope.launch {
val dailyQuote = services.getDalyQuote(currentUserState.langage)
}
//val dailyQuote = DailyQuoteStub.dailyQuote
val titleDalyQuote = stringResource(R.string.TitleHomeDailyQuote) val titleDalyQuote = stringResource(R.string.TitleHomeDailyQuote)
val titleSuggestion = stringResource(R.string.TitleHomeSuggestion) val titleSuggestion = stringResource(R.string.TitleHomeSuggestion)
@ -65,6 +71,7 @@ fun AccueilPage(
isLoading.value = true isLoading.value = true
delay(500) delay(500)
val newQuotes = services.getSomeQuotes(15, page.intValue) val newQuotes = services.getSomeQuotes(15, page.intValue)
Log.d("Accueil",newQuotes.toString())
val uniqueQuotes = newQuotes.filterNot { new -> quotes.any { it.id == new.id } } val uniqueQuotes = newQuotes.filterNot { new -> quotes.any { it.id == new.id } }
if (uniqueQuotes.isNotEmpty()) { if (uniqueQuotes.isNotEmpty()) {
@ -93,10 +100,24 @@ fun AccueilPage(
.background(MaterialTheme.colorScheme.background) .background(MaterialTheme.colorScheme.background)
) { ) {
LazyColumn(modifier = Modifier.weight(1f), state = state) { LazyColumn(modifier = Modifier.weight(1f), state = state) {
item { if(dailyQuote.id!=-1) {
Column(Modifier.clickable { navQuote(dailyQuote.id) }) { item {
Column(Modifier.clickable { navQuote(dailyQuote.id) }) {
Text(
text = titleDalyQuote,
color = MaterialTheme.colorScheme.onBackground,
fontSize = 24.sp,
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
textAlign = TextAlign.Center
)
QuoteLittle(dailyQuote)
}
Text( Text(
text = titleDalyQuote, text = titleSuggestion,
color = MaterialTheme.colorScheme.onBackground, color = MaterialTheme.colorScheme.onBackground,
fontSize = 24.sp, fontSize = 24.sp,
modifier = Modifier modifier = Modifier
@ -104,20 +125,8 @@ fun AccueilPage(
.padding(16.dp), .padding(16.dp),
textAlign = TextAlign.Center textAlign = TextAlign.Center
) )
QuoteLittle(dailyQuote)
} }
Text(
text = titleSuggestion,
color = MaterialTheme.colorScheme.onBackground,
fontSize = 24.sp,
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
textAlign = TextAlign.Center
)
} }
items(quotes) { quote -> items(quotes) { quote ->
if (quote.language == currentUserState.langage) { if (quote.language == currentUserState.langage) {
Column(Modifier.clickable { navQuote(quote.id ) }) { Column(Modifier.clickable { navQuote(quote.id ) }) {

Loading…
Cancel
Save