-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove public user repository, move the search for wire use…
…rs to seperated repository (#319) * use common repository for the WireUser * create wire user repository * remove public user reopsitory * fix the tests * Fix tests * Update logic/src/commonTest/kotlin/com/wire/kalium/logic/data/publicuser/WireUserRepositoryTest.kt Co-authored-by: Alexandre Ferris <[email protected]> * fix review comments * remove extra line * rename the methods * Update logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/wireuser/search/SearchPublicWireUserUseCase.kt Co-authored-by: Alexandre Ferris <[email protected]> * change the name of the repo * fix the naming * Update logic/src/commonMain/kotlin/com/wire/kalium/logic/data/wireuser/SearchUserRepository.kt Co-authored-by: Jacob Persson <[email protected]> * Update logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/wireuser/search/WireUserSearchResult.kt Co-authored-by: Jacob Persson <[email protected]> * Update logic/src/commonMain/kotlin/com/wire/kalium/logic/data/wireuser/SearchUserRepository.kt Co-authored-by: Jacob Persson <[email protected]> * Update network/src/commonMain/kotlin/com/wire/kalium/network/api/contact/search/WireUserSearchApi.kt Co-authored-by: Jacob Persson <[email protected]> * Update network/src/commonMain/kotlin/com/wire/kalium/network/api/contact/search/WireUserSearchApi.kt Co-authored-by: Jacob Persson <[email protected]> * rename * rename * remove prefix * further rename * further rename * remove prefix * test Co-authored-by: mateusz.pachulski <[email protected]> Co-authored-by: Alexandre Ferris <[email protected]> Co-authored-by: Vitor Hugo Schwaab <[email protected]> Co-authored-by: Jacob Persson <[email protected]>
- Loading branch information
1 parent
16858f5
commit 8d95b8f
Showing
25 changed files
with
264 additions
and
253 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
57 changes: 0 additions & 57 deletions
57
logic/src/commonMain/kotlin/com/wire/kalium/logic/data/publicuser/PublicUserRepository.kt
This file was deleted.
Oops, something went wrong.
63 changes: 63 additions & 0 deletions
63
logic/src/commonMain/kotlin/com/wire/kalium/logic/data/publicuser/SearchUserRepository.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,63 @@ | ||
package com.wire.kalium.logic.data.publicuser | ||
|
||
import com.wire.kalium.logic.CoreFailure | ||
import com.wire.kalium.logic.data.publicuser.model.UserSearchResult | ||
import com.wire.kalium.logic.di.MapperProvider | ||
import com.wire.kalium.logic.functional.Either | ||
import com.wire.kalium.logic.functional.suspending | ||
import com.wire.kalium.logic.wrapApiRequest | ||
import com.wire.kalium.network.api.contact.search.UserSearchApi | ||
import com.wire.kalium.network.api.contact.search.UserSearchRequest | ||
import com.wire.kalium.network.api.user.details.ListUserRequest | ||
import com.wire.kalium.network.api.user.details.UserDetailsApi | ||
import com.wire.kalium.network.api.user.details.qualifiedIds | ||
import com.wire.kalium.persistence.dao.UserDAO | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.map | ||
|
||
interface SearchUserRepository { | ||
suspend fun searchKnownUsers(searchQuery: String): Flow<UserSearchResult> | ||
suspend fun searchUserDirectory( | ||
searchQuery: String, | ||
domain: String, | ||
maxResultSize: Int? = null | ||
): Either<CoreFailure, UserSearchResult> | ||
} | ||
|
||
class SearchUserRepositoryImpl( | ||
private val userDAO: UserDAO, | ||
private val userSearchApi: UserSearchApi, | ||
private val userDetailsApi: UserDetailsApi, | ||
private val publicUserMapper: PublicUserMapper = MapperProvider.publicUserMapper() | ||
) : SearchUserRepository { | ||
|
||
override suspend fun searchKnownUsers(searchQuery: String) = | ||
userDAO.getUserByNameOrHandleOrEmail(searchQuery) | ||
.map { | ||
UserSearchResult(it.map { userEntity -> publicUserMapper.fromDaoModelToPublicUser(userEntity) }) | ||
} | ||
|
||
override suspend fun searchUserDirectory( | ||
searchQuery: String, | ||
domain: String, | ||
maxResultSize: Int? | ||
): Either<CoreFailure, UserSearchResult> { | ||
return suspending { | ||
wrapApiRequest { | ||
userSearchApi.search( | ||
UserSearchRequest( | ||
searchQuery = searchQuery, | ||
domain = domain, | ||
maxResultSize = maxResultSize | ||
) | ||
) | ||
}.flatMap { contactResultValue -> | ||
wrapApiRequest { | ||
userDetailsApi.getMultipleUsers(ListUserRequest.qualifiedIds(contactResultValue.documents.map { it.qualifiedID })) | ||
}.map { userDetailsResponses -> | ||
UserSearchResult(publicUserMapper.fromUserDetailResponses(userDetailsResponses)) | ||
} | ||
} | ||
} | ||
} | ||
} |
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
8 changes: 0 additions & 8 deletions
8
...c/commonMain/kotlin/com/wire/kalium/logic/data/publicuser/model/PublicUserSearchResult.kt
This file was deleted.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
logic/src/commonMain/kotlin/com/wire/kalium/logic/data/publicuser/model/UserSearchResult.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,3 @@ | ||
package com.wire.kalium.logic.data.publicuser.model | ||
|
||
data class UserSearchResult(val result : List<PublicUser>) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,5 +20,4 @@ data class SelfUser( | |
val completePicture: UserAssetId? | ||
) : User() | ||
|
||
|
||
typealias UserAssetId = String |
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
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
19 changes: 19 additions & 0 deletions
19
...src/commonMain/kotlin/com/wire/kalium/logic/feature/publicuser/SearchKnownUsersUseCase.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,19 @@ | ||
package com.wire.kalium.logic.feature.publicuser | ||
|
||
import com.wire.kalium.logic.data.publicuser.SearchUserRepository | ||
import com.wire.kalium.logic.data.publicuser.model.UserSearchResult | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
interface SearchKnownUsersUseCase { | ||
suspend operator fun invoke(searchQuery: String): Flow<UserSearchResult> | ||
} | ||
|
||
internal class SearchKnownUsersUseCaseImpl( | ||
private val searchUserRepository: SearchUserRepository | ||
) : SearchKnownUsersUseCase { | ||
|
||
// TODO:this use case is going to be refactor once we return Either from DAO's | ||
override suspend operator fun invoke(searchQuery: String): Flow<UserSearchResult> = | ||
searchUserRepository.searchKnownUsers(searchQuery) | ||
|
||
} |
Oops, something went wrong.