Support retrieving account data whose key starts with a string.

This commit is contained in:
Onuray Sahin 2022-12-09 14:51:23 +03:00
parent b09a00efda
commit 3d68233723
2 changed files with 23 additions and 0 deletions

View File

@ -63,4 +63,17 @@ interface SessionAccountDataService {
* Update the account data with the provided type and the provided account data content. * Update the account data with the provided type and the provided account data content.
*/ */
suspend fun updateUserAccountData(type: String, content: Content) suspend fun updateUserAccountData(type: String, content: Content)
/**
* Retrieve user account data list whose type starts with the given type.
* @param type the type or the starting part of a type
* @return list of account data whose type starts with the given type
*/
fun getUserAccountDataEventsStartWith(type: String): List<UserAccountDataEvent>
/**
* Deletes user account data of the given type.
* @param type the type to delete from user account data
*/
suspend fun deleteUserAccountData(type: String)
} }

View File

@ -60,6 +60,16 @@ internal class UserAccountDataDataSource @Inject constructor(
) )
} }
fun getAccountDataEventsStartWith(type: String): List<UserAccountDataEvent> {
return realmSessionProvider.withRealm { realm ->
realm
.where(UserAccountDataEntity::class.java)
.contains(UserAccountDataEntityFields.TYPE, type)
.findAll()
.map(accountDataMapper::map)
}
}
private fun accountDataEventsQuery(realm: Realm, types: Set<String>): RealmQuery<UserAccountDataEntity> { private fun accountDataEventsQuery(realm: Realm, types: Set<String>): RealmQuery<UserAccountDataEntity> {
val query = realm.where(UserAccountDataEntity::class.java) val query = realm.where(UserAccountDataEntity::class.java)
if (types.isNotEmpty()) { if (types.isNotEmpty()) {