feat(CON-265) : Aligner les flux de l'api d'UI avec les nouveaux dev back
This commit is contained in:
@ -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>
|
@ -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>
|
@ -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)
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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 {
|
||||
|
@ -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"
|
||||
}
|
||||
|
||||
}
|
||||
|
4
consentium/src/prod/res/values/strings.xml
Normal file
4
consentium/src/prod/res/values/strings.xml
Normal 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>
|
Reference in New Issue
Block a user