Integration version api local + nouvelle version
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
|
||||
<application
|
||||
android:usesCleartextTraffic="true"
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
|
||||
@@ -11,7 +11,10 @@ class RetrofitTools {
|
||||
companion object {
|
||||
|
||||
// La racine de l'api
|
||||
val BASE_URL = "https://raw.githubusercontent.com/Chocolaterie/EniWebService/refs/heads/main/api/"
|
||||
//val BASE_URL = "http://127.0.0.1:3000/"
|
||||
|
||||
// Pour les personnes emulateurs :
|
||||
val BASE_URL = "http://10.0.2.2:3000/"
|
||||
|
||||
// L'utilitaire conversion JSON <=> Objet
|
||||
val moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build();
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.example.tpfilrouge.api
|
||||
|
||||
data class ServiceResponseDTO<T>(var code: String, var message : String, var data : T?) {
|
||||
}
|
||||
@@ -1,13 +1,14 @@
|
||||
package com.example.demoandroid.demoapi
|
||||
|
||||
import com.example.tpfilrouge.api.RetrofitTools.Companion.retrofit
|
||||
import com.example.tpfilrouge.api.ServiceResponseDTO
|
||||
import com.example.tpfilrouge.article.Article
|
||||
import retrofit2.http.GET
|
||||
|
||||
interface ArticleService {
|
||||
|
||||
@GET("android-articles.json")
|
||||
suspend fun getArticles() : List<Article>
|
||||
@GET("articles")
|
||||
suspend fun getArticles() : ServiceResponseDTO<List<Article>>
|
||||
|
||||
object ArticleApi {
|
||||
val articleService : ArticleService by lazy { retrofit.create(ArticleService::class.java) }
|
||||
|
||||
@@ -20,8 +20,20 @@ class ListArticleViewModel : ViewModel() {
|
||||
AppDialogHelpers.get().showDialog("Chargement des articles en cours")
|
||||
|
||||
viewModelScope.launch {
|
||||
// Récupérer les articles via un API Web
|
||||
articles.value = ArticleService.ArticleApi.articleService.getArticles();
|
||||
// Récupérer le metier listArticle via un API Web
|
||||
val serviceResponse = ArticleService.ArticleApi.articleService.getArticles();
|
||||
|
||||
// Plus tard il sera possible de tester le code métier
|
||||
/*
|
||||
if (serviceResponse.code.equals("200")) {
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
// La liste des articles ecoutables se met à jour par rapport à la
|
||||
// la liste des articles dans le data
|
||||
// Node : on remaque !! aprés data car data est nullable (!! que si nullable))
|
||||
articles.value = serviceResponse.data!!;
|
||||
|
||||
// Fermer la popup de chargement
|
||||
AppDialogHelpers.get().closeDialog();
|
||||
|
||||
Reference in New Issue
Block a user