-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
265 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
...in/java/com/github/privacyDashboard/communication/repositories/IndividualApiRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...acyDashboard/src/main/java/com/github/privacyDashboard/models/v2/individual/Individual.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
7 changes: 7 additions & 0 deletions
7
...board/src/main/java/com/github/privacyDashboard/models/v2/individual/IndividualRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
10 changes: 10 additions & 0 deletions
10
...src/main/java/com/github/privacyDashboard/models/v2/individual/IndividualsListResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
) |