From c2bbf5f7e798e7a4b79a30a9183f0b700ddcc615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolo=CC=80=20Tosi?= Date: Tue, 16 Jan 2024 18:25:56 +0100 Subject: [PATCH] WIP: added opt-out filter to the contacts' repository --- .../it/bz/noi/community/data/models/Contact.kt | 6 ++++-- .../community/data/repository/MainRepository.kt | 16 +++++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/it/bz/noi/community/data/models/Contact.kt b/app/src/main/java/it/bz/noi/community/data/models/Contact.kt index 3e85679..9d284fe 100644 --- a/app/src/main/java/it/bz/noi/community/data/models/Contact.kt +++ b/app/src/main/java/it/bz/noi/community/data/models/Contact.kt @@ -24,8 +24,10 @@ data class Contact( val email: String?, @SerializedName("_parentcustomerid_value") val accountId: String?, - - val companyName: String? + @SerializedName("companyName") + val companyName: String?, + @SerializedName("app-opt-out") + val appOptOut: Boolean = false, ) : Parcelable data class ContactResponse( diff --git a/app/src/main/java/it/bz/noi/community/data/repository/MainRepository.kt b/app/src/main/java/it/bz/noi/community/data/repository/MainRepository.kt index f6eaf75..a0ed183 100644 --- a/app/src/main/java/it/bz/noi/community/data/repository/MainRepository.kt +++ b/app/src/main/java/it/bz/noi/community/data/repository/MainRepository.kt @@ -7,7 +7,16 @@ package it.bz.noi.community.data.repository import it.bz.noi.community.data.api.ApiHelper import it.bz.noi.community.data.models.* -class MainRepository(private val apiHelper: ApiHelper) { +class MainRepository( + /** + * Remote data source. + */ + private val apiHelper: ApiHelper, + /** + * If enabled, [Contact]s with `appOptOut` set to `true` will be filtered out. + */ + private val isOptOutEnabled: Boolean = false +) { // EVENTS suspend fun getEvents(eventsParams: EventsParams) = apiHelper.getEvents(eventsParams) suspend fun getEventDetails(eventID: String) = apiHelper.getEventDetails(eventID) @@ -23,6 +32,7 @@ class MainRepository(private val apiHelper: ApiHelper) { // CONTACTS suspend fun getAccounts(accessToken: String): List = apiHelper.getAccounts(accessToken).accounts - suspend fun getContacts(accessToken: String): List = apiHelper.getContacts(accessToken).contacts - + suspend fun getContacts(accessToken: String): List = apiHelper.getContacts(accessToken).contacts.let { + if (isOptOutEnabled) it.filter { !it.appOptOut } else it + } }