flix_db/entity/content/
episodes.rs

1//! Episode entity
2
3use flix_model::id::{LibraryId, ShowId};
4
5use seamantic::model::path::PathBytes;
6
7use flix_model::numbers::{EpisodeNumber, SeasonNumber};
8use sea_orm::{
9	ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
10	EnumIter, PrimaryKeyTrait, Related, RelationDef, RelationTrait,
11};
12
13/// The database representation of a episode media folder
14#[derive(Debug, Clone, DeriveEntityModel)]
15#[sea_orm(table_name = "flix_episodes")]
16pub struct Model {
17	/// The episode's show's ID
18	#[sea_orm(primary_key, auto_increment = false)]
19	pub show: ShowId,
20	/// The episode's season's number
21	#[sea_orm(primary_key, auto_increment = false)]
22	pub season: SeasonNumber,
23	/// The episode's number
24	#[sea_orm(primary_key, auto_increment = false)]
25	pub episode: EpisodeNumber,
26	/// The number of additional contained episodes
27	pub count: u8,
28	/// The episode's slug
29	pub slug: String,
30	/// The episode's library
31	pub library: LibraryId,
32	/// The episode's directory
33	pub directory: PathBytes,
34	/// The episode's media path
35	pub relative_media_path: String,
36	/// The episode's poster path
37	pub relative_poster_path: Option<String>,
38}
39
40impl ActiveModelBehavior for ActiveModel {}
41
42/// Relation
43#[derive(Debug, EnumIter, DeriveRelation)]
44pub enum Relation {
45	/// The library this episode belongs to
46	#[sea_orm(
47		belongs_to = "super::libraries::Entity",
48		from = "Column::Library",
49		to = "super::libraries::Column::Id",
50		on_update = "Cascade",
51		on_delete = "Cascade"
52	)]
53	Library,
54	/// The media info for this episode
55	#[sea_orm(
56		belongs_to = "super::super::info::episodes::Entity",
57		from = "(Column::Show, Column::Season, Column::Episode)",
58		to = "(super::super::info::episodes::Column::Show, super::super::info::episodes::Column::Season, super::super::info::episodes::Column::Episode)",
59		on_update = "Cascade",
60		on_delete = "Cascade"
61	)]
62	MediaInfo,
63	/// The watched info for this episode
64	#[sea_orm(
65		belongs_to = "super::super::watched::episodes::Entity",
66		from = "(Column::Show, Column::Season, Column::Episode)",
67		to = "(super::super::watched::episodes::Column::Show, super::super::watched::episodes::Column::Season, super::super::watched::episodes::Column::Episode)",
68		on_update = "Cascade",
69		on_delete = "Cascade"
70	)]
71	WatchInfo,
72}
73
74impl Related<super::libraries::Entity> for Entity {
75	fn to() -> RelationDef {
76		Relation::Library.def()
77	}
78}
79
80impl Related<super::super::info::episodes::Entity> for Entity {
81	fn to() -> RelationDef {
82		Relation::MediaInfo.def()
83	}
84}
85
86impl Related<super::super::watched::episodes::Entity> for Entity {
87	fn to() -> RelationDef {
88		Relation::WatchInfo.def()
89	}
90}