what2watch/src/watches/mod.rs
2023-06-08 15:45:34 -07:00

79 lines
1.5 KiB
Rust

use serde::{Deserialize, Serialize};
use uuid::Uuid;
pub mod handlers;
pub mod templates;
#[derive(
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, sqlx::Type,
)]
#[repr(i32)]
pub enum ShowKind {
Movie = 0,
Series = 1,
LimitedSeries = 2,
Short = 3,
Unknown = 4,
}
impl std::fmt::Display for ShowKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
todo!()
}
}
impl Default for ShowKind {
fn default() -> Self {
Self::Unknown
}
}
impl From<i32> for ShowKind {
fn from(value: i32) -> Self {
match value {
0 => Self::Movie,
1 => Self::Series,
2 => Self::LimitedSeries,
3 => Self::Short,
4 => Self::Unknown,
_ => Self::Unknown,
}
}
}
#[derive(
Debug,
Default,
Clone,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
Serialize,
Deserialize,
sqlx::FromRow,
)]
pub struct Watch {
pub id: Uuid,
pub kind: ShowKind,
pub title: String,
pub metadata_url: Option<String>,
pub length: Option<i32>,
pub release_date: Option<i64>,
added_by: Uuid, // this shouldn't be exposed to randos
created_at: i64,
last_updated: i64,
}
impl Watch {
pub fn new(title: &str, added_by: Uuid) -> Self {
let id = Uuid::new_v4();
Self {
id,
title: title.to_string(),
added_by,
..Default::default()
}
}
}