-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added fetching comprehensive object of movie favorites and marking th…
…em as notified instead of deletion
- Loading branch information
Showing
30 changed files
with
956 additions
and
51 deletions.
There are no files selected for viewing
781 changes: 781 additions & 0 deletions
781
feature-core-database/schemas/movie.core.db.MovieDatabase/16.json
Large diffs are not rendered by default.
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
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
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
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
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 |
---|---|---|
@@ -1,13 +1,17 @@ | ||
package movie.core | ||
|
||
import movie.core.model.Movie | ||
import movie.core.model.MoviePreview | ||
import movie.core.model.MovieFavorite | ||
|
||
interface FavoriteFeature { | ||
|
||
suspend fun isFavorite(movie: Movie): Result<Boolean> | ||
suspend fun toggle(movie: MoviePreview): Result<Boolean> | ||
suspend fun getAll(): Result<List<MoviePreview>> | ||
suspend fun toggle(movie: Movie): Result<Boolean> | ||
suspend fun setNotified(movie: Movie): Result<Unit> | ||
|
||
suspend fun getPending(): Result<List<MovieFavorite>> | ||
suspend fun getAll(): Result<List<MovieFavorite>> | ||
suspend fun get(movie: Movie): Result<MovieFavorite> | ||
|
||
} | ||
|
56 changes: 39 additions & 17 deletions
56
feature-core/src/main/java/movie/core/FavoriteFeatureFromDatabase.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,35 +1,57 @@ | ||
package movie.core | ||
|
||
import movie.core.adapter.MoviePreviewFromDatabase | ||
import movie.core.adapter.MovieFavoriteFromDatabase | ||
import movie.core.adapter.MovieFromDatabase | ||
import movie.core.db.dao.MovieDao | ||
import movie.core.db.dao.MovieFavoriteDao | ||
import movie.core.db.dao.MovieMediaDao | ||
import movie.core.db.model.MovieFavoriteStored | ||
import movie.core.model.Movie | ||
import movie.core.model.MoviePreview | ||
import movie.core.model.MovieFavorite | ||
import java.util.Date | ||
|
||
class FavoriteFeatureFromDatabase( | ||
private val favoriteDao: MovieFavoriteDao, | ||
private val mediaDao: MovieMediaDao | ||
private val movieDao: MovieDao | ||
) : FavoriteFeature { | ||
|
||
override suspend fun isFavorite(movie: Movie): Result<Boolean> = | ||
favoriteDao.runCatching { | ||
isFavorite(movie.id) | ||
override suspend fun isFavorite(movie: Movie): Result<Boolean> = favoriteDao.runCatching { | ||
isFavorite(movie.id) | ||
} | ||
|
||
override suspend fun setNotified(movie: Movie): Result<Unit> { | ||
return favoriteDao.runCatching { setFavorite(movie.id) } | ||
} | ||
|
||
override suspend fun toggle(movie: Movie): Result<Boolean> = favoriteDao.runCatching { | ||
val favorite = MovieFavoriteStored(movie = movie.id, movie.releasedAt.before(Date())) | ||
val isFavorite = isFavorite(movie).getOrThrow() | ||
when (isFavorite) { | ||
true -> delete(favorite) | ||
else -> insertOrUpdate(favorite) | ||
} | ||
!isFavorite | ||
} | ||
|
||
override suspend fun toggle(movie: MoviePreview): Result<Boolean> = | ||
favoriteDao.runCatching { | ||
val favorite = MovieFavoriteStored(movie = movie.id) | ||
val isFavorite = isFavorite(movie).getOrThrow() | ||
when (isFavorite) { | ||
true -> delete(favorite) | ||
else -> insertOrUpdate(favorite) | ||
} | ||
!isFavorite | ||
override suspend fun getPending(): Result<List<MovieFavorite>> = favoriteDao.runCatching { | ||
selectPending().mapNotNull { | ||
val movie = movieDao.select(it.movie)?.let(::MovieFromDatabase) | ||
?: return@mapNotNull null | ||
MovieFavoriteFromDatabase(it, movie) | ||
} | ||
} | ||
|
||
override suspend fun getAll() = runCatching { | ||
favoriteDao.selectAll().map { MoviePreviewFromDatabase(it, mediaDao.select(it.id)) } | ||
favoriteDao.selectAll().mapNotNull { | ||
val movie = movieDao.select(it.movie)?.let(::MovieFromDatabase) | ||
?: return@mapNotNull null | ||
MovieFavoriteFromDatabase(it, movie) | ||
} | ||
} | ||
|
||
override suspend fun get(movie: Movie): Result<MovieFavorite> { | ||
return favoriteDao.runCatching { select(movie.id).let(::requireNotNull) }.mapCatching { | ||
val movie = movieDao.select(it.movie)?.let(::MovieFromDatabase).let(::requireNotNull) | ||
MovieFavoriteFromDatabase(it, 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
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
16 changes: 16 additions & 0 deletions
16
feature-core/src/main/java/movie/core/adapter/MovieFavoriteFromDatabase.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,16 @@ | ||
package movie.core.adapter | ||
|
||
import movie.core.db.model.MovieFavoriteStored | ||
import movie.core.model.Movie | ||
import movie.core.model.MovieFavorite | ||
import java.util.Date | ||
|
||
data class MovieFavoriteFromDatabase( | ||
private val stored: MovieFavoriteStored, | ||
override val movie: Movie | ||
) : MovieFavorite { | ||
override val createdAt: Date | ||
get() = stored.createdAt | ||
override val isNotified: Boolean | ||
get() = stored.notified | ||
} |
23 changes: 23 additions & 0 deletions
23
feature-core/src/main/java/movie/core/adapter/MovieFromDatabase.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,23 @@ | ||
package movie.core.adapter | ||
|
||
import movie.core.db.model.MovieStored | ||
import movie.core.model.Movie | ||
import java.util.Date | ||
import kotlin.time.Duration | ||
|
||
data class MovieFromDatabase( | ||
private val stored: MovieStored | ||
) : Movie { | ||
override val id: String | ||
get() = stored.id | ||
override val name: String | ||
get() = stored.name | ||
override val url: String | ||
get() = stored.url | ||
override val releasedAt: Date | ||
get() = stored.releasedAt | ||
override val screeningFrom: Date | ||
get() = stored.screeningFrom | ||
override val duration: Duration | ||
get() = stored.duration | ||
} |
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
Oops, something went wrong.