Skip to content

Commit

Permalink
Make CharacterLocalContract, CharacterLocalRoomDataSource and Charact…
Browse files Browse the repository at this point in the history
…erLocalDAO return Unit for favorite and unfavorite
  • Loading branch information
othiagosouto committed Dec 10, 2023
1 parent 459782a commit 9638a1e
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal interface CharacterLocalDAO {
fun favoriteList(): Flow<List<CharacterLocal>>

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun favorite(item: CharacterLocal): Long
suspend fun favorite(item: CharacterLocal): Unit

@Query("SELECT id FROM ${CharacterLocal.TABLE_NAME}")
fun favoriteIds(): Flow<List<Long>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ import kotlinx.coroutines.flow.map
internal class CharacterLocalRoomDataSource(private val characterDAO: CharacterLocalDAO) :
CharacterLocalContract<Character> {

override suspend fun favorite(item: Character): Long =
override suspend fun favorite(item: Character): Unit =
characterDAO.favorite(item.toCharacterLocal())

override fun favoriteIds(): Flow<List<Long>> = characterDAO.favoriteIds()

override suspend fun unFavorite(item: Character): Long {
override suspend fun unFavorite(item: Character) =
characterDAO.unFavorite(item.toCharacterLocal())
return item.id
}

override fun favoritesList(): Flow<List<Character>> =
characterDAO.favoriteList().map(::characterAdapter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface CharacterLocalContract<T : Any> {
/**
* favorite character and returns its id
*/
suspend fun favorite(item: T): Long
suspend fun favorite(item: T): Unit

/**
* return a list of favorite ids
Expand All @@ -26,5 +26,5 @@ interface CharacterLocalContract<T : Any> {
/**
* unfavorite character and returns its id
*/
suspend fun unFavorite(item: T): Long
suspend fun unFavorite(item: T): Unit
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal class DefaultFavoritesService(
*/
override suspend fun unFavorite(
item: Character
) {
) : Unit {
localDataSource.unFavorite(item)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,12 @@ internal class DefaultFavoritesServiceTest {

override fun favoriteIds(): Flow<List<Long>> = flowOf(characters.map { it.id })

override suspend fun unFavorite(item: Character): Long {
override suspend fun unFavorite(item: Character): Unit {
characters.remove(item)
return item.id
}

override suspend fun favorite(item: Character): Long {
override suspend fun favorite(item: Character): Unit {
characters.add(item)
return item.id
}
}
}

0 comments on commit 9638a1e

Please sign in to comment.