Compare commits
13 Commits
Author | SHA1 | Date |
---|---|---|
|
feffbde59b | 1 year ago |
|
6d35a221e5 | 1 year ago |
|
0df14fb03f | 1 year ago |
|
bbb1dbfa10 | 1 year ago |
|
76a51f1de0 | 1 year ago |
|
67e405e7e0 | 1 year ago |
|
d7e40b049f | 1 year ago |
|
656c9cb4ae | 1 year ago |
|
880ce7c38c | 1 year ago |
|
af3ff9dacc | 1 year ago |
![]() |
5cfc57e864 | 1 year ago |
![]() |
b69f2bf3ea | 1 year ago |
![]() |
2d231a4402 | 1 year ago |
@ -1,11 +0,0 @@
|
||||
package com.example.veraxapplication.data
|
||||
/*
|
||||
data class Article(
|
||||
var Title : String,
|
||||
var Description : String,
|
||||
var Image : String,
|
||||
var Author : String,
|
||||
var Content : List<Paragraph>,
|
||||
var LectureTime : String
|
||||
)
|
||||
*/
|
@ -1,6 +0,0 @@
|
||||
package com.example.veraxapplication.data
|
||||
/*
|
||||
data class Paragraph(
|
||||
var Content : String,
|
||||
)
|
||||
*/
|
@ -0,0 +1,27 @@
|
||||
package com.example.veraxapplication.modele
|
||||
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
|
||||
object RetrofitClientUser {
|
||||
|
||||
private const val BASE_URL = "https://codefirst.iut.uca.fr/containers/Verax-verax-api"
|
||||
|
||||
val retrofit: Retrofit by lazy {
|
||||
Retrofit.Builder()
|
||||
.baseUrl(BASE_URL)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.build()
|
||||
}
|
||||
|
||||
// interface UserApiService {
|
||||
// @GET("users")
|
||||
// suspend fun getUsers() : List<User>
|
||||
// }
|
||||
}
|
||||
|
||||
object ApiClientUser {
|
||||
val apiService: UserApiService by lazy {
|
||||
RetrofitClientUser.retrofit.create(UserApiService::class.java)
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.example.veraxapplication.modele
|
||||
|
||||
import com.example.veraxapplication.modele.user.User
|
||||
import retrofit2.Call
|
||||
import retrofit2.http.GET
|
||||
|
||||
interface UserApiService {
|
||||
@GET("users/")
|
||||
suspend fun getUsers(): Call<List<User>>
|
||||
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package com.example.veraxapplication.modele.api
|
||||
|
||||
import com.example.veraxapplication.modele.user.User
|
||||
import retrofit2.Call
|
||||
import retrofit2.http.GET
|
||||
|
||||
interface IUserService {
|
||||
@GET("users")
|
||||
suspend fun getUsers(): List<UserDTO>
|
||||
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package com.example.veraxapplication.modele.api
|
||||
|
||||
import com.example.veraxapplication.modele.user.User
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class UserDTO (
|
||||
|
||||
@SerializedName("pseudo")
|
||||
val pseudo: String,
|
||||
@SerializedName("mdp")
|
||||
val mdp: String,
|
||||
@SerializedName("mail")
|
||||
val mail: String,
|
||||
@SerializedName("nom")
|
||||
val nom: String,
|
||||
@SerializedName("prenom")
|
||||
val prenom: String,
|
||||
@SerializedName("role")
|
||||
val role: String,
|
||||
|
||||
) {
|
||||
fun toModel(): User {
|
||||
return User(
|
||||
pseudo,
|
||||
mdp,
|
||||
mail,
|
||||
nom,
|
||||
prenom,
|
||||
role,
|
||||
)
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
package com.example.veraxapplication.modele.api
|
||||
|
||||
import android.util.Log
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.example.veraxapplication.modele.articles.Article
|
||||
import com.example.veraxapplication.modele.user.User
|
||||
import kotlinx.coroutines.launch
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.logging.HttpLoggingInterceptor
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
|
||||
object RetrofitClientUser {
|
||||
|
||||
private const val BASE_URL = "https://codefirst.iut.uca.fr/containers/Verax-verax-api"
|
||||
|
||||
private val logging = HttpLoggingInterceptor().apply {
|
||||
level = HttpLoggingInterceptor.Level.BODY
|
||||
}
|
||||
|
||||
private val httpClient = OkHttpClient.Builder().apply {
|
||||
addInterceptor(logging)
|
||||
}.build()
|
||||
|
||||
|
||||
val retrofit: Retrofit by lazy {
|
||||
Retrofit.Builder()
|
||||
.baseUrl(BASE_URL)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.build()
|
||||
}
|
||||
|
||||
// interface UserApiService {
|
||||
// @GET("users")
|
||||
// suspend fun getUsers() : List<User>
|
||||
// }
|
||||
}
|
||||
|
||||
class UsersViewModel : ViewModel() {
|
||||
private val _users = MutableLiveData<List<User>>()
|
||||
val users: LiveData<List<User>> = _users
|
||||
|
||||
private val service = ArticleApiClient.retrofit.create(IUserService::class.java)
|
||||
|
||||
init {
|
||||
loadUsers()
|
||||
}
|
||||
|
||||
fun loadUsers() {
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
val usersDto = service.getUsers() // Pas besoin d'appeler .execute()
|
||||
// Convertissez les DTO en modèles de données si nécessaire
|
||||
_users.value = usersDto.map { it.toModel() }
|
||||
} catch (e: Exception) {
|
||||
Log.e("UsersViewModel", "Erreur lors du chargement des users", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
|
||||
import com.example.veraxapplication.modele.IArticlesDataManager
|
||||
import com.example.veraxapplication.modele.articles.Article
|
||||
import com.example.veraxapplication.modele.articles.contenus.Contenu
|
||||
import com.example.veraxapplication.modele.articles.contenus.ContenuMedia
|
||||
import com.example.veraxapplication.modele.articles.contenus.ContenuParagraphe
|
||||
import com.example.veraxapplication.modele.user.User
|
||||
|
||||
|
||||
class StubUsers() : IUsersDataManager {
|
||||
private var lUsers: MutableList<User>? = null
|
||||
|
||||
init {
|
||||
chargerUsers()
|
||||
}
|
||||
|
||||
|
||||
private fun chargerUsers() {
|
||||
lUsers = java.util.ArrayList<User>()
|
||||
val user1 = User (
|
||||
"NoaSil",
|
||||
"1234",
|
||||
"",
|
||||
"Sillard",
|
||||
"Noa",
|
||||
"Admin"
|
||||
)
|
||||
lUsers!!.add(user1)
|
||||
val user2 = User (
|
||||
"Sha",
|
||||
"1234",
|
||||
"",
|
||||
"Cascarra",
|
||||
"Shana",
|
||||
"Admin"
|
||||
)
|
||||
lUsers!!.add(user2)
|
||||
val user3 = User (
|
||||
"TonyF",
|
||||
"1234",
|
||||
"tony@gmail.com",
|
||||
"Fages",
|
||||
"Tony",
|
||||
"Admin"
|
||||
)
|
||||
lUsers!!.add(user3)
|
||||
val user4 = User (
|
||||
"JeanSwaggLaPuissance63",
|
||||
"1234",
|
||||
"jean.lapuissance@gmail.com",
|
||||
"Marcillac",
|
||||
"Jean",
|
||||
"Admin"
|
||||
)
|
||||
lUsers!!.add(user4)
|
||||
}
|
||||
|
||||
override val allUsers: List<User>?
|
||||
get() = lUsers
|
||||
|
||||
override fun getUser(pseudo : String): User? {
|
||||
println("Passage dans getUser avec comme pseudo : $pseudo")
|
||||
lUsers?.let {
|
||||
println("Nombre d'utilisateurs disponibles : ${it.size}")
|
||||
|
||||
val userARenvoyer: User? = it.find { user -> user.pseudo == pseudo }
|
||||
|
||||
return userARenvoyer
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
override fun getUsers(): List<User>
|
||||
{
|
||||
return lUsers?.takeIf { it.isNotEmpty() }?.take(lUsers!!.size) ?: emptyList()
|
||||
}
|
||||
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
package com.example.veraxapplication.modele.user
|
||||
|
||||
data class User(val pseudo : String, val mdp : String, val mail : String, val nom : String, val prenom : String, val role : String)
|
||||
data class User(val pseudo : String, val mdp : String, val mail : String, val nom : String, val prenom : String, val role : Char)
|
@ -1,23 +0,0 @@
|
||||
package com.example.veraxapplication.ui.connexion
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextField
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.example.veraxapplication.modele.user.User
|
||||
|
||||
@Composable
|
||||
fun AfficherForm(users : List<User>) {
|
||||
var pseudo = "DEFAULT"
|
||||
var mdp = "DEFAULT"
|
||||
Column {
|
||||
TextField(value = "Pseudo", onValueChange = { value -> pseudo = value }, modifier = Modifier.padding(5.dp))
|
||||
TextField(value = "Mot de passe", onValueChange = { value -> mdp = value }, modifier = Modifier.padding(5.dp))
|
||||
for (u in users) {
|
||||
Text(text = u.pseudo)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
<resources>
|
||||
<string name="app_name">Verax</string>
|
||||
<string name="app_name">VeraxApplication</string>
|
||||
</resources>
|
Loading…
Reference in new issue