Skip to content

Commit

Permalink
Add: #201 - function to Optin to Data Agreement
Browse files Browse the repository at this point in the history
  • Loading branch information
josmilan authored and georgepadayatti committed Nov 13, 2023
1 parent 12ef6e1 commit 25220b6
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package com.github.privacyDashboard
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.res.Resources
import android.util.Log
import com.github.privacyDashboard.communication.BBConsentAPIManager
import com.github.privacyDashboard.communication.BBConsentAPIServices
import com.github.privacyDashboard.communication.repositories.UpdateDataAgreementStatusApiRepository
import com.github.privacyDashboard.models.v2.consent.ConsentStatusRequestV2
import com.github.privacyDashboard.modules.home.BBConsentDashboardActivity
import com.github.privacyDashboard.utils.BBConsentDataUtils
import com.github.privacyDashboard.utils.BBConsentDataUtils.EXTRA_TAG_ACCESS_TOKEN
Expand All @@ -15,6 +17,8 @@ import com.github.privacyDashboard.utils.BBConsentDataUtils.EXTRA_TAG_ENABLE_USE
import com.github.privacyDashboard.utils.BBConsentDataUtils.EXTRA_TAG_TOKEN
import com.github.privacyDashboard.utils.BBConsentDataUtils.EXTRA_TAG_USERID
import com.github.privacyDashboard.utils.BBConsentLocaleHelper
import com.google.gson.Gson


object PrivacyDashboard {

Expand Down Expand Up @@ -164,4 +168,40 @@ object PrivacyDashboard {
fun setLocale(context: Context, languageCode: String) {
BBConsentLocaleHelper.setLocale(context, languageCode)
}

suspend fun optInToDataAgreement(
dataAgreementId: String,
baseUrl: String,
accessToken: String? = null,
apiKey: String? = null,
userId: String? = null,
): String? {
val body = ConsentStatusRequestV2()
body.optIn = false

val apiService: BBConsentAPIServices = BBConsentAPIManager.getApi(
apiKey = apiKey,
accessToken = accessToken,
baseUrl = (if (baseUrl.last().toString() == "/")
baseUrl
else
"$baseUrl/")
)?.service!!

val updateDataAgreementStatusApiRepository =
UpdateDataAgreementStatusApiRepository(apiService)

val result = updateDataAgreementStatusApiRepository.updateDataAgreementStatus(
userId = userId,
dataAgreementId = dataAgreementId,
body = body
)

return if (result.isSuccess) {
Gson().toJson(result.getOrNull()?.dataAgreementRecord)
} else {
null
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ interface BBConsentAPIServices {

@PUT("service/individual/record/consent-record/{dataAgreementRecordId}")
suspend fun setOverallStatusV2(
@Header("X-ConsentBB-IndividualId") userID: String?,
@Header("X-ConsentBB-IndividualId") userID: String? = null,
@Path("dataAgreementRecordId") dataAgreementRecordId: String?,
@Query("dataAgreementId") dataAgreementId: String?,
@Body body: ConsentStatusRequestV2?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class UpdateDataAgreementStatusApiRepository(private val apiService: BBConsentAP
return try {
val dataAgreementRecord = apiService.getDataAgreementRecordV2(userId, dataAgreementId)
var response: Response<DataAgreementLatestRecordResponseV2?>? = null
if (dataAgreementRecord?.isSuccessful != true) {
if (dataAgreementRecord?.isSuccessful != true || dataAgreementRecord.body()?.dataAgreementRecord == null) {
response = apiService.createDataAgreementRecordV2(userId, dataAgreementId)
} else {
response = apiService.setOverallStatusV2(
Expand Down

0 comments on commit 25220b6

Please sign in to comment.