parent
aa95ce53a2
commit
22de81e373
@ -1,22 +0,0 @@
|
||||
package com.example.veraxapplication.modele
|
||||
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
|
||||
object RetrofitClient {
|
||||
|
||||
private const val BASE_URL = "http://181.214.189.133:9092/"
|
||||
|
||||
val retrofit: Retrofit by lazy {
|
||||
Retrofit.Builder()
|
||||
.baseUrl(BASE_URL)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
object ApiClient {
|
||||
val apiService: ApiService by lazy {
|
||||
RetrofitClient.retrofit.create(ApiService::class.java)
|
||||
}
|
||||
}
|
@ -1,12 +1,11 @@
|
||||
package com.example.veraxapplication.modele
|
||||
|
||||
import com.example.veraxapplication.modele.articles.Article
|
||||
import com.example.veraxapplication.modele.user.User
|
||||
import retrofit2.Call
|
||||
import retrofit2.http.GET
|
||||
|
||||
interface UserApiService {
|
||||
@GET("users/")
|
||||
fun getUsers(): Call<List<User>>
|
||||
suspend fun getUsers(): Call<List<User>>
|
||||
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package com.example.veraxapplication.modele.api
|
||||
|
||||
import com.example.veraxapplication.modele.articles.Article
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class ArticleDTO (
|
||||
|
||||
@SerializedName("id")
|
||||
val id: Int,
|
||||
@SerializedName("titre")
|
||||
val titre: String,
|
||||
@SerializedName("description")
|
||||
val description: String,
|
||||
@SerializedName("imagePrincipale")
|
||||
val imagePrincipale: String,
|
||||
@SerializedName("date")
|
||||
val date: String,
|
||||
@SerializedName("auteur")
|
||||
val auteur: String,
|
||||
@SerializedName("contenu")
|
||||
val contenu: List<ContenuDTO>,
|
||||
@SerializedName("temps")
|
||||
val temps: String,
|
||||
@SerializedName("note")
|
||||
val note: String,
|
||||
) {
|
||||
fun toModel(): Article {
|
||||
return Article(
|
||||
id,
|
||||
titre,
|
||||
description,
|
||||
auteur,
|
||||
date,
|
||||
imagePrincipale,
|
||||
temps,
|
||||
note,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
data class ContenuDTO (
|
||||
@SerializedName("id")
|
||||
val id: Int,
|
||||
@SerializedName("typeContenu")
|
||||
val typeContenu: String,
|
||||
@SerializedName("titre")
|
||||
val titre: String,
|
||||
@SerializedName("texte")
|
||||
val texte: String,
|
||||
)
|
@ -0,0 +1,5 @@
|
||||
package com.example.veraxapplication.modele.api
|
||||
|
||||
class ArticleRepository {
|
||||
|
||||
}
|
@ -1,11 +1,10 @@
|
||||
package com.example.veraxapplication.modele
|
||||
package com.example.veraxapplication.modele.api
|
||||
|
||||
import com.example.veraxapplication.modele.articles.Article
|
||||
import retrofit2.Call
|
||||
import retrofit2.http.GET
|
||||
|
||||
interface ApiService {
|
||||
interface IArticleAPI {
|
||||
@GET("articles/")
|
||||
fun getArticles(): Call<List<Article>>
|
||||
|
||||
}
|
Loading…
Reference in new issue