feat(CON-265) : Aligner les flux de l'api d'UI avec les nouveaux dev back

This commit is contained in:
2025-02-11 17:00:53 +01:00
parent c57c9b7d05
commit af91841857
36 changed files with 144 additions and 176 deletions

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<string name="backend_url" translatable="false" tools:ignore="UnusedResources">https://consentium-api-dev.openium.fr/api/v1/app</string>
<resources>
<string name="backend_url" translatable="false">https://consentium-api-dev.openium.fr/api/v1/app/</string>
</resources>

View File

@ -1,4 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
</manifest>

View File

@ -15,7 +15,8 @@ import kotlinx.coroutines.flow.asStateFlow
class Consentium(
context: Context,
val applicationId: String,
val apiKey: String,
val appId: String,
) {
private val _fetchConsentState = MutableStateFlow<FetchConsentiumState>(FetchConsentiumState.Idle)
val fetchConsentState by lazy { _fetchConsentState.asStateFlow() }
@ -32,7 +33,7 @@ class Consentium(
suspend fun fetchConsents() {
_fetchConsentState.value = FetchConsentiumState.Loading
try {
when (val consentResponse = consentiumRepository.getConsents(applicationId)) {
when (val consentResponse = consentiumRepository.getConsents(apiKey)) {
ConsentiumRepositoryGetResponse.Error -> _fetchConsentState.value = FetchConsentiumState.Error
is ConsentiumRepositoryGetResponse.GetConsentsSuccess -> {
@ -54,7 +55,7 @@ class Consentium(
) {
_saveConsentState.emit(SetConsentiumState.Loading)
try {
when (consentiumRepository.setConsents(applicationId, consent)) {
when (consentiumRepository.setConsents(apiKey, consent)) {
ConsentiumRepositorySetResponse.Error -> {
_saveConsentState.emit(SetConsentiumState.Error)
}

View File

@ -11,12 +11,12 @@ import retrofit2.http.POST
internal interface ConsentiumApi {
@GET("/consents")
@GET("consents")
suspend fun getConsents(
@Header("Authorization") token: String,
): Response<GetConsent.GetConsentPayloadDTO>
@POST("/consents")
@POST("consents")
suspend fun setConsents(
@Header("Authorization") token: String,
@Body patchConsent: PatchConsent.PatchConsentPayloadDTO,

View File

@ -7,7 +7,7 @@ internal sealed interface GetConsent {
@Serializable
data class GetConsentPayloadDTO(
@SerialName("id") val id: String,
@SerialName("id") val id: String? = null,
@SerialName("installationId") val installationId: String,
@SerialName("state") val state: ConsentStateDTO? = null,
@SerialName("acceptedDate") val acceptedData: Long? = null,

View File

@ -16,10 +16,11 @@ internal class ConsentiumRepository @Inject constructor(
private val getAuthTokenUseCase: GetAuthTokenUseCase,
) {
suspend fun getConsents(applicationId: String): ConsentiumRepositoryGetResponse {
val authToken = getAuthTokenUseCase(applicationId)
val consentsResponse = consentiumApi.getConsents(authToken)
suspend fun getConsents(apiKey: String): ConsentiumRepositoryGetResponse {
return try {
val authToken = getAuthTokenUseCase(apiKey)
val consentsResponse = consentiumApi.getConsents(authToken)
val consentsBody = if (consentsResponse.isSuccessful) {
consentsResponse.body() ?: throw Exception()
} else {

View File

@ -5,7 +5,7 @@ import kotlin.io.encoding.Base64
import kotlin.io.encoding.ExperimentalEncodingApi
interface GetAuthTokenUseCase {
suspend operator fun invoke(applicationId: String): String
suspend operator fun invoke(apiKey: String): String
}
class GetAuthTokenUseCaseImpl @Inject internal constructor(
@ -13,11 +13,11 @@ class GetAuthTokenUseCaseImpl @Inject internal constructor(
) : GetAuthTokenUseCase {
@OptIn(ExperimentalEncodingApi::class)
override suspend operator fun invoke(applicationId: String): String {
override suspend operator fun invoke(apiKey: String): String {
val uniqueInstallationId = getConsentiumUniqueInstallationIdUseCase()
val clearToken = "$applicationId.$uniqueInstallationId"
val clearToken = "$apiKey.$uniqueInstallationId"
val cipheredToken = Base64.Default.encode(clearToken.toByteArray())
return "Bearer $cipheredToken"
return "Basic $cipheredToken"
}
}

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<string name="backend_url" translatable="false" tools:ignore="UnusedResources">https://consentium-api.openium.fr/api/v1/app/</string>
</resources>