- Add MovieDAO, SerieDAO, SeasonDAO and EpisodeDAO - Add Entity for Movie, Serie, Season and Episode - Add MediaDatabasemaster
parent
55f48d7975
commit
ce46396e37
@ -0,0 +1,7 @@
|
||||
package com.example.cinapp.Room.DAO
|
||||
|
||||
import androidx.room.Dao
|
||||
|
||||
@Dao
|
||||
interface EpisodeDAO {
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package com.example.cinapp.Room.DAO
|
||||
|
||||
import androidx.room.*
|
||||
import com.example.cinapp.Room.Entity.MovieEntity
|
||||
|
||||
@Dao
|
||||
interface MovieDAO {
|
||||
|
||||
@Query("SELECT * FROM movie")
|
||||
fun getAll(): List<MovieEntity>
|
||||
|
||||
@Query("SELECT * FROM movie WHERE id IN (:movieIds)")
|
||||
fun loadAllByIds(movieIds: IntArray): List<MovieEntity>
|
||||
|
||||
@Query("SELECT * FROM movie WHERE name LIKE :name LIMIT 1")
|
||||
fun findByName(name: String): MovieEntity
|
||||
|
||||
@Query("SELECT * FROM movie WHERE id LIKE :id LIMIT 1")
|
||||
fun findById(id: Int): MovieEntity
|
||||
|
||||
@Query("SELECT * FROM movie WHERE :genreId IN (genreIds)")
|
||||
fun findByGenre(genreId: Int): List<MovieEntity>
|
||||
|
||||
@Query("SELECT * FROM movie WHERE :genreId IN (genreIds)")
|
||||
fun findByGenres(genreId: List<Int>): List<MovieEntity>
|
||||
|
||||
@Update
|
||||
fun updateMovie(movie: MovieEntity)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun insertAll(vararg movies: MovieEntity)
|
||||
|
||||
@Query("DELETE FROM movie")
|
||||
fun deleteAll()
|
||||
|
||||
@Query("DELETE FROM movie WHERE id LIKE :id")
|
||||
fun deleteById(id: Int)
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.example.cinapp.Room.DAO
|
||||
|
||||
import androidx.room.Dao
|
||||
|
||||
@Dao
|
||||
interface SeasonDAO {
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.example.cinapp.Room.DAO
|
||||
|
||||
import androidx.room.*
|
||||
import com.example.cinapp.Room.Entity.SerieEntity
|
||||
|
||||
@Dao
|
||||
interface SerieDAO {
|
||||
@Query("SELECT * FROM serie")
|
||||
fun getAll(): List<SerieEntity>
|
||||
|
||||
@Query("SELECT * FROM serie WHERE id IN (:serieIds)")
|
||||
fun loadAllByIds(serieIds: IntArray): List<SerieEntity>
|
||||
|
||||
@Query("SELECT * FROM serie WHERE name LIKE :name LIMIT 1")
|
||||
fun findByName(name: String): SerieEntity
|
||||
|
||||
@Query("SELECT * FROM serie WHERE id LIKE :id LIMIT 1")
|
||||
fun findById(id: Int): SerieEntity
|
||||
|
||||
@Query("SELECT * FROM serie WHERE :genreId IN (genreIds)")
|
||||
fun findByGenre(genreId: Int): List<SerieEntity>
|
||||
|
||||
@Query("SELECT * FROM serie WHERE :genreId IN (genreIds)")
|
||||
fun findByGenres(genreId: List<Int>): List<SerieEntity>
|
||||
|
||||
@Query("SELECT * FROM serie WHERE :seasonId IN (seasonsIds)")
|
||||
fun findBySeason(seasonId: Int): SerieEntity
|
||||
|
||||
@Query("SELECT * FROM serie " +
|
||||
"WHERE :episodeId IN (" +
|
||||
"SELECT episodesIds FROM season WHERE id IN (" +
|
||||
"SELECT seasonsIds FROM serie WHERE :episodeId IN (" +
|
||||
"SELECT episodesIds FROM season)))")
|
||||
fun findByEpisode(episodeId: Int): SerieEntity
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.example.cinapp.Room.Entity
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "season")
|
||||
data class EpisodeEntity (
|
||||
@PrimaryKey var id: Int,
|
||||
var name: String,
|
||||
var overview: String,
|
||||
var stillPath: String,
|
||||
var episodeNumber: Int,
|
||||
var seasonNumber: Int,
|
||||
var airDate: String,
|
||||
var voteAverage: Double,
|
||||
var voteCount: Int
|
||||
)
|
@ -0,0 +1,21 @@
|
||||
package com.example.cinapp.Room.Entity
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "movie")
|
||||
data class MovieEntity (
|
||||
@PrimaryKey val id: Int,
|
||||
val name: String,
|
||||
val backdropPath: String,
|
||||
val releaseDate: String,
|
||||
val originCountry: List<String>,
|
||||
val originalLanguage: String,
|
||||
val originalName: String,
|
||||
val overview: String,
|
||||
val popularity: Double,
|
||||
val posterPath: String,
|
||||
val voteAverage: Double,
|
||||
val voteCount: Int,
|
||||
val genreIds: List<Int>
|
||||
)
|
@ -0,0 +1,14 @@
|
||||
package com.example.cinapp.Room.Entity
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "season")
|
||||
data class SeasonEntity (
|
||||
@PrimaryKey var id: Int,
|
||||
var name: String,
|
||||
var overview: String,
|
||||
var posterPath: String,
|
||||
var seasonNumber: Int,
|
||||
var episodesIds: List<Int>
|
||||
)
|
@ -0,0 +1,24 @@
|
||||
package com.example.cinapp.Room.Entity
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "serie")
|
||||
data class SerieEntity (
|
||||
@PrimaryKey val id: Int,
|
||||
val name: String,
|
||||
val backdropPath: String,
|
||||
val releaseDate: String,
|
||||
val originCountry: List<String>,
|
||||
val originalLanguage: String,
|
||||
val originalName: String,
|
||||
val overview: String,
|
||||
val popularity: Double,
|
||||
val posterPath: String,
|
||||
val voteAverage: Double,
|
||||
val voteCount: Int,
|
||||
val genreIds: List<Int>,
|
||||
var seasonsIds: List<Int>,
|
||||
var numberOfSeasons: Int,
|
||||
var numberOfEpisodes: Int
|
||||
)
|
@ -0,0 +1,20 @@
|
||||
package com.example.cinapp.Room
|
||||
|
||||
import androidx.room.Database
|
||||
import androidx.room.RoomDatabase
|
||||
import com.example.cinapp.Room.DAO.EpisodeDAO
|
||||
import com.example.cinapp.Room.DAO.MovieDAO
|
||||
import com.example.cinapp.Room.DAO.SeasonDAO
|
||||
import com.example.cinapp.Room.DAO.SerieDAO
|
||||
import com.example.cinapp.Room.Entity.EpisodeEntity
|
||||
import com.example.cinapp.Room.Entity.MovieEntity
|
||||
import com.example.cinapp.Room.Entity.SeasonEntity
|
||||
import com.example.cinapp.Room.Entity.SerieEntity
|
||||
|
||||
@Database(entities = [SeasonEntity::class, EpisodeEntity::class, MovieEntity::class, SerieEntity::class], version = 1)
|
||||
abstract class MediaDatabase: RoomDatabase() {
|
||||
abstract fun seasonDAO(): SeasonDAO
|
||||
abstract fun episodeDAO(): EpisodeDAO
|
||||
abstract fun movieDAO(): MovieDAO
|
||||
abstract fun serieDAO(): SerieDAO
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.example.cinapp.model
|
||||
|
||||
class Episode(
|
||||
var id: Int,
|
||||
var name: String,
|
||||
var overview: String,
|
||||
var stillPath: String,
|
||||
var episodeNumber: Int,
|
||||
var seasonNumber: Int,
|
||||
var airDate: String,
|
||||
var voteAverage: Double,
|
||||
var voteCount: Int
|
||||
) {
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.example.cinapp.model
|
||||
|
||||
abstract class Media {
|
||||
abstract val id: Int
|
||||
abstract val name: String
|
||||
abstract val backdropPath: String
|
||||
abstract val releaseDate: String
|
||||
abstract val originCountry: List<String>
|
||||
abstract val originalLanguage: String
|
||||
abstract val originalName: String
|
||||
abstract val overview : String
|
||||
abstract val popularity: Double
|
||||
abstract val posterPath: String
|
||||
abstract val voteAverage: Double
|
||||
abstract val voteCount: Int
|
||||
abstract val genreIds: List<Int>
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package com.example.cinapp.model
|
||||
|
||||
class MediasLibrary(
|
||||
var id : Int,
|
||||
var mediasLibrary: List<Media>
|
||||
){
|
||||
override fun toString(): String {
|
||||
return "MediasLibrary(id=$id, mediasLibrary=$mediasLibrary)"
|
||||
}
|
||||
|
||||
//add a media to the library
|
||||
fun addMedia(media: Media){
|
||||
mediasLibrary += media
|
||||
}
|
||||
|
||||
//remove a media from the library
|
||||
fun removeMedia(media: Media){
|
||||
mediasLibrary -= media
|
||||
}
|
||||
|
||||
//get a media from the library
|
||||
fun getMedia(media: Media): Media?{
|
||||
return mediasLibrary.find { it.id == media.id }
|
||||
}
|
||||
|
||||
//get all medias from the library
|
||||
fun getAllMedias(): List<Media>{
|
||||
return mediasLibrary
|
||||
}
|
||||
|
||||
//get all medias from the library
|
||||
fun getAllMediasByType(type: String): List<Media>{
|
||||
var medias = mutableListOf<Media>()
|
||||
for (media in mediasLibrary){
|
||||
if (media is Movie && type == "movie"){
|
||||
medias.add(media)
|
||||
}
|
||||
if (media is Serie && type == "serie"){
|
||||
medias.add(media)
|
||||
}
|
||||
}
|
||||
return medias
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.example.cinapp.model
|
||||
|
||||
class Movie(
|
||||
override val id: Int,
|
||||
override val name: String,
|
||||
override val backdropPath: String,
|
||||
override val releaseDate: String,
|
||||
override val originCountry: List<String>,
|
||||
override val originalLanguage: String,
|
||||
override val originalName: String,
|
||||
override val overview: String,
|
||||
override val popularity: Double,
|
||||
override val posterPath: String,
|
||||
override val voteAverage: Double,
|
||||
override val voteCount: Int,
|
||||
override val genreIds: List<Int>
|
||||
) : Media() {
|
||||
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.example.cinapp.model
|
||||
|
||||
class Season(
|
||||
var id: Int,
|
||||
var name: String,
|
||||
var overview: String,
|
||||
var posterPath: String,
|
||||
var seasonNumber: Int,
|
||||
var episodes: List<Episode>
|
||||
) {
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.example.cinapp.model
|
||||
|
||||
class Serie(
|
||||
override val id: Int,
|
||||
override val name: String,
|
||||
override val backdropPath: String,
|
||||
override val releaseDate: String,
|
||||
override val originCountry: List<String>,
|
||||
override val originalLanguage: String,
|
||||
override val originalName: String,
|
||||
override val overview: String,
|
||||
override val popularity: Double,
|
||||
override val posterPath: String,
|
||||
override val voteAverage: Double,
|
||||
override val voteCount: Int,
|
||||
override val genreIds: List<Int>,
|
||||
var seasons: List<Season>,
|
||||
var numberOfSeasons: Int,
|
||||
var numberOfEpisodes: Int
|
||||
) : Media() {
|
||||
}
|
Loading…
Reference in new issue