what2watch/src/watches/mod.rs
2024-04-07 14:01:31 -07:00

106 lines
2.5 KiB
Rust

use julid::Julid;
use serde::{Deserialize, Serialize};
pub mod handlers;
pub mod templates;
#[derive(
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, sqlx::Type,
)]
#[repr(i8)]
pub enum ShowKind {
Movie = 0,
Series = 1,
LimitedSeries = 2,
Short = 3,
Unknown = 4,
Other = 5,
}
impl std::fmt::Display for ShowKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let repr = match self {
Self::Movie => "movie",
Self::Series => "series",
Self::LimitedSeries => "limited series",
Self::Short => "short form",
Self::Other => "other",
Self::Unknown => "unknown",
};
write!(f, "{repr}")
}
}
impl Default for ShowKind {
fn default() -> Self {
Self::Unknown
}
}
impl From<i64> for ShowKind {
fn from(value: i64) -> Self {
match value {
0 => Self::Movie,
1 => Self::Series,
2 => Self::LimitedSeries,
3 => Self::Short,
4 => Self::Unknown,
5 => Self::Other,
_ => Self::Unknown,
}
}
}
//-************************************************************************
/// Something able to be watched.
//-************************************************************************
#[derive(
Debug,
Default,
Clone,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
Serialize,
Deserialize,
sqlx::FromRow,
)]
pub struct Watch {
pub id: Julid,
pub title: String,
pub kind: ShowKind,
pub metadata_url: Option<String>,
pub length: Option<i64>,
pub release_date: Option<String>,
pub added_by: Julid, // this shouldn't be exposed to randos in the application
}
//-************************************************************************
/// Something a user wants to watch
//-************************************************************************
#[derive(
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, sqlx::FromRow,
)]
pub struct WatchQuest {
pub user: Julid,
pub watch: Julid,
pub public: bool,
pub watched: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct QuestId {
pub user: Julid,
pub watch: Julid,
}
impl WatchQuest {
pub fn id(&self) -> QuestId {
QuestId {
user: self.user,
watch: self.watch,
}
}
}