-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement CinemaxDatabase and UpcomingMovie (#60)
* Add Constants * Add UpcomingMovieEntity * Add UpcomingMovieRemoteKeyEntity * Add UpcomingMovieDao * Add UpcomingMovieRemoteKeyDao * Add Converters * Implement CinemaxDatabase
- Loading branch information
1 parent
b2ba2d9
commit 5d2dde3
Showing
7 changed files
with
275 additions
and
0 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
42 changes: 42 additions & 0 deletions
42
...src/main/kotlin/com/maximillianleonov/cinemax/data/local/dao/upcoming/UpcomingMovieDao.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,42 @@ | ||
/* | ||
* Copyright 2022 Maximillian Leonov | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.maximillianleonov.cinemax.data.local.dao.upcoming | ||
|
||
import androidx.paging.PagingSource | ||
import androidx.room.Dao | ||
import androidx.room.Insert | ||
import androidx.room.OnConflictStrategy | ||
import androidx.room.Query | ||
import com.maximillianleonov.cinemax.core.data.local.common.ContentDao | ||
import com.maximillianleonov.cinemax.core.data.util.Constants.Tables.UPCOMING_MOVIES_TABLE | ||
import com.maximillianleonov.cinemax.data.local.entity.upcoming.UpcomingMovieEntity | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
@Dao | ||
interface UpcomingMovieDao : ContentDao<UpcomingMovieEntity> { | ||
@Query("SELECT * FROM $UPCOMING_MOVIES_TABLE") | ||
override fun getAll(): Flow<List<UpcomingMovieEntity>> | ||
|
||
@Query("SELECT * FROM $UPCOMING_MOVIES_TABLE") | ||
override fun getAllPaging(): PagingSource<Int, UpcomingMovieEntity> | ||
|
||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
override suspend fun insertAll(entities: List<UpcomingMovieEntity>) | ||
|
||
@Query("DELETE FROM $UPCOMING_MOVIES_TABLE") | ||
override suspend fun deleteAll() | ||
} |
37 changes: 37 additions & 0 deletions
37
...kotlin/com/maximillianleonov/cinemax/data/local/dao/upcoming/UpcomingMovieRemoteKeyDao.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,37 @@ | ||
/* | ||
* Copyright 2022 Maximillian Leonov | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.maximillianleonov.cinemax.data.local.dao.upcoming | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Insert | ||
import androidx.room.OnConflictStrategy | ||
import androidx.room.Query | ||
import com.maximillianleonov.cinemax.core.data.local.common.RemoteKeyDao | ||
import com.maximillianleonov.cinemax.core.data.util.Constants.Tables.UPCOMING_MOVIES_REMOTE_KEYS_TABLE | ||
import com.maximillianleonov.cinemax.data.local.entity.upcoming.UpcomingMovieRemoteKeyEntity | ||
|
||
@Dao | ||
interface UpcomingMovieRemoteKeyDao : RemoteKeyDao<UpcomingMovieRemoteKeyEntity> { | ||
@Query("SELECT * FROM $UPCOMING_MOVIES_REMOTE_KEYS_TABLE WHERE id = :id") | ||
override suspend fun getById(id: Int): UpcomingMovieRemoteKeyEntity | ||
|
||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
override suspend fun insertAll(entities: List<UpcomingMovieRemoteKeyEntity>) | ||
|
||
@Query("DELETE FROM $UPCOMING_MOVIES_REMOTE_KEYS_TABLE") | ||
override suspend fun deleteAll() | ||
} |
42 changes: 42 additions & 0 deletions
42
...data-local/src/main/kotlin/com/maximillianleonov/cinemax/data/local/db/CinemaxDatabase.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,42 @@ | ||
/* | ||
* Copyright 2022 Maximillian Leonov | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.maximillianleonov.cinemax.data.local.db | ||
|
||
import androidx.room.Database | ||
import androidx.room.RoomDatabase | ||
import androidx.room.TypeConverters | ||
import com.maximillianleonov.cinemax.data.local.dao.upcoming.UpcomingMovieDao | ||
import com.maximillianleonov.cinemax.data.local.dao.upcoming.UpcomingMovieRemoteKeyDao | ||
import com.maximillianleonov.cinemax.data.local.entity.upcoming.UpcomingMovieEntity | ||
import com.maximillianleonov.cinemax.data.local.entity.upcoming.UpcomingMovieRemoteKeyEntity | ||
|
||
@Database( | ||
entities = [ | ||
UpcomingMovieEntity::class, UpcomingMovieRemoteKeyEntity::class | ||
], | ||
version = 1, | ||
exportSchema = false | ||
) | ||
@TypeConverters(Converters::class) | ||
abstract class CinemaxDatabase : RoomDatabase() { | ||
abstract val upcomingMovieDao: UpcomingMovieDao | ||
abstract val upcomingMovieRemoteKeyDao: UpcomingMovieRemoteKeyDao | ||
|
||
companion object { | ||
const val CINEMAX_DATABASE = "cinemax.db" | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
data/data-local/src/main/kotlin/com/maximillianleonov/cinemax/data/local/db/Converters.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,36 @@ | ||
/* | ||
* Copyright 2022 Maximillian Leonov | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.maximillianleonov.cinemax.data.local.db | ||
|
||
import androidx.room.TypeConverter | ||
import com.maximillianleonov.cinemax.core.data.remote.common.JsonParser | ||
import com.maximillianleonov.cinemax.core.data.remote.serializer.LocalDateSerializer | ||
import kotlinx.datetime.LocalDate | ||
|
||
object Converters { | ||
@TypeConverter | ||
fun localDateToJson(value: LocalDate): String = JsonParser.toJson(LocalDateSerializer(), value) | ||
|
||
@TypeConverter | ||
fun jsonToLocalDate(json: String): LocalDate = JsonParser.fromJson(LocalDateSerializer(), json) | ||
|
||
@TypeConverter | ||
fun intListToJson(value: List<Int>): String = JsonParser.toJson(value) | ||
|
||
@TypeConverter | ||
fun jsonToIntList(json: String): List<Int> = JsonParser.fromJson(json) | ||
} |
73 changes: 73 additions & 0 deletions
73
...in/kotlin/com/maximillianleonov/cinemax/data/local/entity/upcoming/UpcomingMovieEntity.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,73 @@ | ||
/* | ||
* Copyright 2022 Maximillian Leonov | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.maximillianleonov.cinemax.data.local.entity.upcoming | ||
|
||
import androidx.room.ColumnInfo | ||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
import com.maximillianleonov.cinemax.core.data.local.common.MovieEntity | ||
import com.maximillianleonov.cinemax.core.data.util.Constants | ||
import kotlinx.datetime.LocalDate | ||
|
||
@Entity(tableName = Constants.Tables.UPCOMING_MOVIES_TABLE) | ||
data class UpcomingMovieEntity( | ||
@PrimaryKey(autoGenerate = true) | ||
@ColumnInfo(name = Constants.Fields.ID) | ||
override val id: Int = 0, | ||
|
||
@ColumnInfo(name = Constants.Fields.REMOTE_ID) | ||
override val remoteId: Int, | ||
|
||
@ColumnInfo(name = Constants.Fields.TITLE) | ||
override val title: String, | ||
|
||
@ColumnInfo(name = Constants.Fields.OVERVIEW) | ||
override val overview: String, | ||
|
||
@ColumnInfo(name = Constants.Fields.POPULARITY) | ||
override val popularity: Double, | ||
|
||
@ColumnInfo(name = Constants.Fields.RELEASE_DATE) | ||
override val releaseDate: LocalDate, | ||
|
||
@ColumnInfo(name = Constants.Fields.ADULT) | ||
override val adult: Boolean, | ||
|
||
@ColumnInfo(name = Constants.Fields.GENRE_IDS) | ||
override val genreIds: List<Int>, | ||
|
||
@ColumnInfo(name = Constants.Fields.ORIGINAL_TITLE) | ||
override val originalTitle: String, | ||
|
||
@ColumnInfo(name = Constants.Fields.ORIGINAL_LANGUAGE) | ||
override val originalLanguage: String, | ||
|
||
@ColumnInfo(name = Constants.Fields.VOTE_AVERAGE) | ||
override val voteAverage: Double, | ||
|
||
@ColumnInfo(name = Constants.Fields.VOTE_COUNT) | ||
override val voteCount: Int, | ||
|
||
@ColumnInfo(name = Constants.Fields.POSTER_PATH) | ||
override val posterPath: String?, | ||
|
||
@ColumnInfo(name = Constants.Fields.BACKDROP_PATH) | ||
override val backdropPath: String?, | ||
|
||
@ColumnInfo(name = Constants.Fields.VIDEO) | ||
override val video: Boolean | ||
) : MovieEntity |
36 changes: 36 additions & 0 deletions
36
.../com/maximillianleonov/cinemax/data/local/entity/upcoming/UpcomingMovieRemoteKeyEntity.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,36 @@ | ||
/* | ||
* Copyright 2022 Maximillian Leonov | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.maximillianleonov.cinemax.data.local.entity.upcoming | ||
|
||
import androidx.room.ColumnInfo | ||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
import com.maximillianleonov.cinemax.core.data.local.common.RemoteKeyEntity | ||
import com.maximillianleonov.cinemax.core.data.util.Constants | ||
|
||
@Entity(tableName = Constants.Tables.UPCOMING_MOVIES_REMOTE_KEYS_TABLE) | ||
data class UpcomingMovieRemoteKeyEntity( | ||
@PrimaryKey(autoGenerate = false) | ||
@ColumnInfo(name = Constants.Fields.ID) | ||
override val id: Int, | ||
|
||
@ColumnInfo(name = Constants.Fields.PREV_PAGE) | ||
override val prevPage: Int?, | ||
|
||
@ColumnInfo(name = Constants.Fields.NEXT_PAGE) | ||
override val nextPage: Int? | ||
) : RemoteKeyEntity |