Skip to content

Commit

Permalink
Add: #181 - Exposed individual APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
josmilan committed Nov 15, 2023
1 parent 432b73a commit f5da919
Show file tree
Hide file tree
Showing 6 changed files with 265 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import android.content.Intent
import com.github.privacyDashboard.communication.BBConsentAPIManager
import com.github.privacyDashboard.communication.BBConsentAPIServices
import com.github.privacyDashboard.communication.repositories.GetDataAgreementApiRepository
import com.github.privacyDashboard.communication.repositories.IndividualApiRepository
import com.github.privacyDashboard.communication.repositories.UpdateDataAgreementStatusApiRepository
import com.github.privacyDashboard.models.DataAgreementPolicyModel
import com.github.privacyDashboard.models.interfaces.dataAttributesList.DataAgreement
import com.github.privacyDashboard.models.v2.consent.ConsentStatusRequestV2
import com.github.privacyDashboard.models.v2.dataAgreement.DataAgreementV2
import com.github.privacyDashboard.models.v2.individual.IndividualRequest
import com.github.privacyDashboard.modules.dataAgreementPolicy.BBConsentDataAgreementPolicyActivity
import com.github.privacyDashboard.modules.home.BBConsentDashboardActivity
import com.github.privacyDashboard.utils.BBConsentDataUtils
Expand Down Expand Up @@ -359,4 +361,94 @@ object PrivacyDashboard {
}

}

suspend fun createAnIndividual(
accessToken: String? = null,
apiKey: String? = null,
baseUrl: String? = null,
name: String? = null,
email: String? = null,
phone: String? = null
): String? {
val apiService: BBConsentAPIServices = BBConsentAPIManager.getApi(
accessToken,
apiKey,
baseUrl
)?.service!!

val individualApiRepository = IndividualApiRepository(apiService)

val result =
individualApiRepository.createAnIndividual(
name, email, phone
)
return Gson().toJson(result?.getOrNull())
}

suspend fun fetchTheIndividual(
accessToken: String? = null,
apiKey: String? = null,
baseUrl: String? = null,
individualId: String
): String? {
val apiService: BBConsentAPIServices = BBConsentAPIManager.getApi(
accessToken,
apiKey,
baseUrl
)?.service!!

val individualApiRepository = IndividualApiRepository(apiService)

val result =
individualApiRepository.readTheIndividual(
individualId
)
return Gson().toJson(result?.getOrNull())
}

suspend fun updateTheIndividual(
accessToken: String? = null,
apiKey: String? = null,
baseUrl: String? = null,
name: String,
email: String,
phone: String,
individualId: String
): String? {
val apiService: BBConsentAPIServices = BBConsentAPIManager.getApi(
accessToken,
apiKey,
baseUrl
)?.service!!

val individualApiRepository = IndividualApiRepository(apiService)

val result =
individualApiRepository.updateIndividual(
individualId, name, email, phone
)
return Gson().toJson(result?.getOrNull())
}

suspend fun getAllIndividuals(
accessToken: String? = null,
apiKey: String? = null,
baseUrl: String? = null,
offset: Int?,
limit: Int?
): String? {
val apiService: BBConsentAPIServices = BBConsentAPIManager.getApi(
accessToken,
apiKey,
baseUrl
)?.service!!

val individualApiRepository = IndividualApiRepository(apiService)

val result =
individualApiRepository.getAllIndividuals(
offset, limit
)
return Gson().toJson(result?.getOrNull())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.github.privacyDashboard.models.v2.dataAgreement.dataAgreementRecords.
import com.github.privacyDashboard.models.v2.dataAgreement.dataAgreementRecords.DataAgreementRecordsResponseV2
import com.github.privacyDashboard.models.v2.dataAgreement.dataAttributes.DataAttributesListResponseV2
import com.github.privacyDashboard.models.v2.dataAgreement.organization.OrganizationResponseV2
import com.github.privacyDashboard.models.v2.individual.IndividualRequest
import retrofit2.Response
import retrofit2.http.*

Expand Down Expand Up @@ -157,4 +158,26 @@ interface BBConsentAPIServices {
@Path("orgId") orgId: String?,
@Path("requestId") requestId: String?
): Response<UserRequestGenResponseV1?>?

@POST("service/individual")
suspend fun createAnIndividual(
@Body body: IndividualRequest?
): Response<IndividualRequest?>?

@GET("service/individual/{individualId}")
suspend fun readAnIndividual(
@Path("individualId") individualId: String?,
): Response<IndividualRequest?>?

@PUT("service/individual/{individualId}")
suspend fun updateAnIndividual(
@Body body: IndividualRequest?,
@Path("individualId") individualId: String?,
): Response<IndividualRequest?>?

@GET("service/individuals")
suspend fun getAllIndividual(
@Query("offset") offset: Int?,
@Query("limit") limit: Int?,
): Response<IndividualRequest?>?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package com.github.privacyDashboard.communication.repositories

import com.github.privacyDashboard.communication.BBConsentAPIServices
import com.github.privacyDashboard.models.interfaces.userRequests.UserRequestGenResponse
import com.github.privacyDashboard.models.v2.individual.Individual
import com.github.privacyDashboard.models.v2.individual.IndividualRequest

class IndividualApiRepository(private val apiService: BBConsentAPIServices) {

suspend fun createAnIndividual(
name: String?,
email: String?,
phone: String?
): Result<IndividualRequest?>? {
return try {
val individual = IndividualRequest(
individual = Individual(
name = name,
email = email,
phone = phone
)
)
val response = apiService.createAnIndividual(
individual
)
if (response?.isSuccessful == true) {
val data = response.body()
if (data != null) {
Result.success(data)
} else {
Result.failure(Exception("Response body is null"))
}
} else {
Result.failure(Exception("Request failed with code: ${response?.code()}"))
}
} catch (e: Exception) {
Result.failure(e)
}
}

suspend fun readTheIndividual(
individualId: String?
): Result<IndividualRequest?>? {
return try {
val response = apiService.readAnIndividual(
individualId = individualId
)
if (response?.isSuccessful == true) {
val data = response.body()
if (data != null) {
Result.success(data)
} else {
Result.failure(Exception("Response body is null"))
}
} else {
Result.failure(Exception("Request failed with code: ${response?.code()}"))
}
} catch (e: Exception) {
Result.failure(e)
}
}

suspend fun updateIndividual(
individualId: String?,
name: String,
email: String,
phone: String
): Result<IndividualRequest?>? {
return try {
val individual = IndividualRequest(
individual = Individual(
name = name,
email = email,
phone = phone
)
)
val response = apiService.updateAnIndividual(
individualId = individualId,
body = individual
)
if (response?.isSuccessful == true) {
val data = response.body()
if (data != null) {
Result.success(data)
} else {
Result.failure(Exception("Response body is null"))
}
} else {
Result.failure(Exception("Request failed with code: ${response?.code()}"))
}
} catch (e: Exception) {
Result.failure(e)
}
}

suspend fun getAllIndividuals(
offset:Int?,
limit:Int?
): Result<IndividualRequest?>? {
return try {
val response = apiService.getAllIndividual(
offset = offset,
limit = limit
)
if (response?.isSuccessful == true) {
val data = response.body()
if (data != null) {
Result.success(data)
} else {
Result.failure(Exception("Response body is null"))
}
} else {
Result.failure(Exception("Request failed with code: ${response?.code()}"))
}
} catch (e: Exception) {
Result.failure(e)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.github.privacyDashboard.models.v2.individual

import com.google.gson.annotations.SerializedName

data class Individual(
@SerializedName("id") var id: String? = null,
@SerializedName("externalId") var externalId: String? = null,
@SerializedName("externalIdType") var externalIdType: String? = null,
@SerializedName("identityProviderId") var identityProviderId: String? = null,
@SerializedName("name") var name: String? = null,
@SerializedName("iamId") var iamId: String? = null,
@SerializedName("email") var email: String? = null,
@SerializedName("phone") var phone: String? = null,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.github.privacyDashboard.models.v2.individual

import com.google.gson.annotations.SerializedName

data class IndividualRequest(
@SerializedName("individual") var individual: Individual? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.github.privacyDashboard.models.v2.individual

import com.github.privacyDashboard.models.v2.PaginationV2
import com.google.gson.annotations.SerializedName

data class IndividualsListResponse(
@SerializedName("individuals") var individuals: ArrayList<Individual>? = null,
@SerializedName("pagination") var pagination: PaginationV2? = null

)

0 comments on commit f5da919

Please sign in to comment.