feat(CON-267) : Aligner les flux de post des consentements

This commit is contained in:
Louis Legrand 2025-02-11 17:21:24 +01:00
parent af91841857
commit 9f9a66451f
6 changed files with 48 additions and 16 deletions

View File

@ -6,5 +6,4 @@ import fr.openium.consentium.data.remote.model.PatchConsent
internal fun PurposeChoice.toPatchConsentPurposeDTO() = PatchConsent.PurposeDTO( internal fun PurposeChoice.toPatchConsentPurposeDTO() = PatchConsent.PurposeDTO(
identifier = purposeIdentifier, identifier = purposeIdentifier,
choice = choice.toPurposeStatusDTO(), choice = choice.toPurposeStatusDTO(),
vendors = vendors.map { it.toPatchConsentVendorDTO() }
) )

View File

@ -20,6 +20,6 @@ internal interface ConsentiumApi {
suspend fun setConsents( suspend fun setConsents(
@Header("Authorization") token: String, @Header("Authorization") token: String,
@Body patchConsent: PatchConsent.PatchConsentPayloadDTO, @Body patchConsent: PatchConsent.PatchConsentPayloadDTO,
): Response<Any> ): Response<Unit>
} }

View File

@ -32,7 +32,7 @@ internal object ConsentiumMockApi : ConsentiumApi {
return Response.success(consents) return Response.success(consents)
} }
override suspend fun setConsents(token: String, patchConsent: PatchConsent.PatchConsentPayloadDTO): Response<Any> { override suspend fun setConsents(token: String, patchConsent: PatchConsent.PatchConsentPayloadDTO): Response<Unit> {
delay(2000) delay(2000)
return Response.success(Unit) return Response.success(Unit)
} }

View File

@ -14,7 +14,6 @@ internal sealed interface PatchConsent {
data class PurposeDTO( data class PurposeDTO(
@SerialName("identifier") val identifier: String, @SerialName("identifier") val identifier: String,
@SerialName("choice") val choice: PurposeStatusDTO, @SerialName("choice") val choice: PurposeStatusDTO,
@SerialName("vendors") val vendors: List<VendorDTO>? = null,
) )
@Serializable @Serializable

View File

@ -9,6 +9,7 @@ import fr.openium.consentium.api.model.PurposeChoice
import fr.openium.consentium.data.remote.ConsentiumApi import fr.openium.consentium.data.remote.ConsentiumApi
import fr.openium.consentium.data.remote.model.PatchConsent import fr.openium.consentium.data.remote.model.PatchConsent
import fr.openium.consentium.domain.useCase.GetAuthTokenUseCase import fr.openium.consentium.domain.useCase.GetAuthTokenUseCase
import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
internal class ConsentiumRepository @Inject constructor( internal class ConsentiumRepository @Inject constructor(
@ -17,7 +18,6 @@ internal class ConsentiumRepository @Inject constructor(
) { ) {
suspend fun getConsents(apiKey: String): ConsentiumRepositoryGetResponse { suspend fun getConsents(apiKey: String): ConsentiumRepositoryGetResponse {
return try { return try {
val authToken = getAuthTokenUseCase(apiKey) val authToken = getAuthTokenUseCase(apiKey)
val consentsResponse = consentiumApi.getConsents(authToken) val consentsResponse = consentiumApi.getConsents(authToken)
@ -37,23 +37,28 @@ internal class ConsentiumRepository @Inject constructor(
} }
suspend fun setConsents( suspend fun setConsents(
applicationId: String, apiKey: String,
consents: List<PurposeChoice>, consents: List<PurposeChoice>,
): ConsentiumRepositorySetResponse { ): ConsentiumRepositorySetResponse {
val authToken = getAuthTokenUseCase(applicationId) return try {
val authToken = getAuthTokenUseCase(apiKey)
val setConsentResponse = consentiumApi.setConsents( val setConsentResponse = consentiumApi.setConsents(
token = authToken, token = authToken,
patchConsent = PatchConsent.PatchConsentPayloadDTO( patchConsent = PatchConsent.PatchConsentPayloadDTO(
purposes = consents.map { it.toPatchConsentPurposeDTO() }, purposes = consents.map { it.toPatchConsentPurposeDTO() },
)
) )
)
return if (setConsentResponse.isSuccessful) { if (setConsentResponse.isSuccessful) {
ConsentiumRepositorySetResponse.SetConsentsSuccess ConsentiumRepositorySetResponse.SetConsentsSuccess
} else { } else {
ConsentiumRepositorySetResponse.Error
}
} catch (e: Exception) {
Timber.d(e)
ConsentiumRepositorySetResponse.Error ConsentiumRepositorySetResponse.Error
} }
} }
} }

View File

@ -0,0 +1,29 @@
package fr.openium.consentium
import android.content.Context
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import fr.openium.consentium.data.di.ConsentiumUrl
import fr.openium.consentium.data.di.NetworkModule
import okhttp3.HttpUrl
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.OkHttpClient
@Module
@InstallIn(SingletonComponent::class)
object ReleaseNetworkModule {
@Provides
fun provideOkHttpBuilder(@ApplicationContext context: Context): OkHttpClient.Builder {
return NetworkModule.standardOkHttpBuilder(context)
}
@ConsentiumUrl
@Provides
fun okHttpUrlConsentium(@ApplicationContext context: Context): HttpUrl =
context.getString(R.string.backend_url).toHttpUrl()
}