what2watch/src/watches/mod.rs

74 lines
1.4 KiB
Rust
Raw Normal View History

2023-06-05 23:32:42 +00:00
use serde::{Deserialize, Serialize};
use uuid::Uuid;
2023-06-08 16:17:11 +00:00
pub mod handlers;
pub mod templates;
2023-06-05 23:32:42 +00:00
#[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 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()
}
}
}