-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reference #6, move Search classes to new mapping with RemoteDataSource
- Loading branch information
1 parent
ec06b59
commit af4c2b8
Showing
27 changed files
with
225 additions
and
119 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
32 changes: 32 additions & 0 deletions
32
app/src/main/java/com/zsoltbertalan/flickslate/search/data/SearchDataModule.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,32 @@ | ||
package com.zsoltbertalan.flickslate.search.data | ||
|
||
import com.zsoltbertalan.flickslate.search.data.api.GenreDataSource | ||
import com.zsoltbertalan.flickslate.search.data.api.GenreMoviesDataSource | ||
import com.zsoltbertalan.flickslate.search.data.db.GenreDao | ||
import com.zsoltbertalan.flickslate.search.data.db.GenreMoviesDao | ||
import com.zsoltbertalan.flickslate.search.data.network.GenreMoviesRemoteDataSource | ||
import com.zsoltbertalan.flickslate.search.data.network.GenreRemoteDataSource | ||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
interface SearchDataModule { | ||
|
||
@Binds | ||
fun bindGenreDataSource(genreDao: GenreDao): GenreDataSource.Local | ||
|
||
@Binds | ||
fun bindGenreRemoteDataSource(genreRemoteDataSource: GenreRemoteDataSource): GenreDataSource.Remote | ||
|
||
@Binds | ||
fun bindGenreMoviesDataSource(genreMoviesDao: GenreMoviesDao): GenreMoviesDataSource.Local | ||
|
||
@Binds | ||
fun bindGenreMoviesRemoteDataSource( | ||
genreMoviesRemoteDataSource: GenreMoviesRemoteDataSource | ||
): GenreMoviesDataSource.Remote | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
app/src/main/java/com/zsoltbertalan/flickslate/search/data/api/GenreDataSource.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,32 @@ | ||
package com.zsoltbertalan.flickslate.search.data.api | ||
|
||
import com.zsoltbertalan.flickslate.shared.domain.model.Genre | ||
import com.zsoltbertalan.flickslate.shared.domain.model.GenresReply | ||
import com.zsoltbertalan.flickslate.shared.util.Outcome | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
interface GenreDataSource { | ||
|
||
interface Local { | ||
|
||
suspend fun purgeDatabase() | ||
|
||
suspend fun insertGenres(genres: List<Genre>) | ||
|
||
suspend fun insertEtag(etag: String) | ||
|
||
suspend fun getEtag(): String | ||
|
||
fun getGenres(): Flow<GenresReply> | ||
|
||
fun getGenre(id: String): Genre | ||
|
||
} | ||
|
||
interface Remote { | ||
|
||
suspend fun getGenres(etag: String): Outcome<GenresReply> | ||
|
||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
app/src/main/java/com/zsoltbertalan/flickslate/search/data/api/GenreMoviesDataSource.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,29 @@ | ||
package com.zsoltbertalan.flickslate.search.data.api | ||
|
||
import com.zsoltbertalan.flickslate.movies.domain.model.Movie | ||
import com.zsoltbertalan.flickslate.shared.domain.model.PageData | ||
import com.zsoltbertalan.flickslate.shared.domain.model.PagingReply | ||
import com.zsoltbertalan.flickslate.shared.util.Outcome | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
interface GenreMoviesDataSource { | ||
|
||
interface Local { | ||
|
||
suspend fun purgeDatabase() | ||
|
||
suspend fun insertGenreMovies(movies: List<Movie>, page: Int) | ||
|
||
suspend fun insertGenreMoviesPageData(page: PageData) | ||
|
||
fun getGenreMovies(page: Int): Flow<PagingReply<Movie>?> | ||
|
||
} | ||
|
||
interface Remote { | ||
|
||
suspend fun getGenreMovies(genreId: Int, page: Int?): Outcome<PagingReply<Movie>> | ||
|
||
} | ||
|
||
} |
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
20 changes: 0 additions & 20 deletions
20
app/src/main/java/com/zsoltbertalan/flickslate/search/data/db/GenreDataSource.kt
This file was deleted.
Oops, something went wrong.
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
18 changes: 0 additions & 18 deletions
18
app/src/main/java/com/zsoltbertalan/flickslate/search/data/db/GenreMoviesDataSource.kt
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
app/src/main/java/com/zsoltbertalan/flickslate/search/data/db/SearchDatabaseModule.kt
This file was deleted.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
...main/java/com/zsoltbertalan/flickslate/search/data/network/GenreMoviesRemoteDataSource.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,27 @@ | ||
package com.zsoltbertalan.flickslate.search.data.network | ||
|
||
import com.zsoltbertalan.flickslate.movies.data.network.model.MoviesReplyDto | ||
import com.zsoltbertalan.flickslate.movies.data.network.model.toMoviesReply | ||
import com.zsoltbertalan.flickslate.movies.domain.model.Movie | ||
import com.zsoltbertalan.flickslate.search.data.api.GenreMoviesDataSource | ||
import com.zsoltbertalan.flickslate.shared.domain.model.PagingReply | ||
import com.zsoltbertalan.flickslate.shared.util.Outcome | ||
import com.zsoltbertalan.flickslate.shared.util.safeCallWithMetadata | ||
import retrofit2.Response | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
class GenreMoviesRemoteDataSource @Inject constructor( | ||
private val searchService: SearchService | ||
) : GenreMoviesDataSource.Remote { | ||
|
||
override suspend fun getGenreMovies(genreId: Int, page: Int?): Outcome<PagingReply<Movie>> { | ||
return safeCallWithMetadata( | ||
{ searchService.getGenreMovie(withGenres = genreId, page = page) }, | ||
Response<MoviesReplyDto>::toMoviesReply | ||
) | ||
} | ||
|
||
} | ||
|
26 changes: 26 additions & 0 deletions
26
app/src/main/java/com/zsoltbertalan/flickslate/search/data/network/GenreRemoteDataSource.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,26 @@ | ||
package com.zsoltbertalan.flickslate.search.data.network | ||
|
||
import com.zsoltbertalan.flickslate.search.data.api.GenreDataSource | ||
import com.zsoltbertalan.flickslate.search.data.network.model.GenreReplyDto | ||
import com.zsoltbertalan.flickslate.search.data.network.model.toGenresReply | ||
import com.zsoltbertalan.flickslate.shared.domain.model.GenresReply | ||
import com.zsoltbertalan.flickslate.shared.util.Outcome | ||
import com.zsoltbertalan.flickslate.shared.util.safeCallWithMetadata | ||
import retrofit2.Response | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
class GenreRemoteDataSource @Inject constructor( | ||
private val searchService: SearchService | ||
) : GenreDataSource.Remote { | ||
|
||
override suspend fun getGenres(etag: String): Outcome<GenresReply> { | ||
return safeCallWithMetadata( | ||
{ searchService.getGenres(ifNoneMatch = etag) }, | ||
Response<GenreReplyDto>::toGenresReply | ||
) | ||
} | ||
|
||
} | ||
|
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
13 changes: 12 additions & 1 deletion
13
app/src/main/java/com/zsoltbertalan/flickslate/search/data/network/model/GenreReplyDto.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 |
---|---|---|
@@ -1,11 +1,22 @@ | ||
package com.zsoltbertalan.flickslate.search.data.network.model | ||
|
||
import com.babestudios.base.data.mapNullInputList | ||
import com.zsoltbertalan.flickslate.movies.data.network.model.toMoviesReply | ||
import com.zsoltbertalan.flickslate.shared.domain.model.Genre | ||
import com.zsoltbertalan.flickslate.shared.domain.model.GenresReply | ||
import kotlinx.serialization.Serializable | ||
import retrofit2.Response | ||
|
||
@Serializable | ||
data class GenreReplyDto( | ||
val genres: List<GenreDto> = emptyList(), | ||
) | ||
|
||
fun GenreReplyDto.toGenres(): List<Genre> = this.genres.toGenreList() | ||
fun GenreReplyDto.toGenres(): List<Genre> = this.genres.toGenresReply() | ||
|
||
fun Response<GenreReplyDto>.toGenresReply(): GenresReply { | ||
val body = this.body()!! | ||
val genres = body.genres | ||
val etag = this.headers()["etag"] ?: "" | ||
return GenresReply(genres.map { it.toGenre() }, etag) | ||
} |
6 changes: 3 additions & 3 deletions
6
app/src/main/java/com/zsoltbertalan/flickslate/search/domain/api/GenreRepository.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 |
---|---|---|
@@ -1,14 +1,14 @@ | ||
package com.zsoltbertalan.flickslate.search.domain.api | ||
|
||
import com.zsoltbertalan.flickslate.shared.util.Outcome | ||
import com.zsoltbertalan.flickslate.shared.domain.model.Genre | ||
import com.zsoltbertalan.flickslate.movies.domain.model.Movie | ||
import com.zsoltbertalan.flickslate.shared.domain.model.GenresReply | ||
import com.zsoltbertalan.flickslate.shared.domain.model.PagingReply | ||
import com.zsoltbertalan.flickslate.shared.util.Outcome | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
interface GenreRepository { | ||
|
||
fun getGenresList(): Flow<Outcome<List<Genre>>> | ||
fun getGenresList(): Flow<Outcome<GenresReply>> | ||
fun getGenreDetail(genreId: Int, page: Int): Flow<Outcome<PagingReply<Movie>>> | ||
|
||
} |
Oops, something went wrong.