From 1a4ffaa99d011011e1344d9fdc629d7017e0dfc5 Mon Sep 17 00:00:00 2001 From: Joe Ardent Date: Mon, 5 Jun 2023 16:32:42 -0700 Subject: [PATCH] adds Watches struct --- migrations/20230426221940_init.up.sql | 10 ++-- src/lib.rs | 1 + src/main.rs | 4 +- src/watches/handlers.rs | 1 + src/watches/mod.rs | 74 +++++++++++++++++++++++++++ 5 files changed, 84 insertions(+), 6 deletions(-) create mode 100644 src/watches/handlers.rs create mode 100644 src/watches/mod.rs diff --git a/migrations/20230426221940_init.up.sql b/migrations/20230426221940_init.up.sql index 7d53573..f94e598 100644 --- a/migrations/20230426221940_init.up.sql +++ b/migrations/20230426221940_init.up.sql @@ -20,11 +20,13 @@ create table if not exists watches ( id blob not null primary key, typ int not null, -- enum for movie or tv show or whatev title text not null, - imdb text, -- possible url for imdb or other metadata-esque site to show the user - runtime int, + metadata_url text, -- possible url for imdb or other metadata-esque site to show the user + length int, release_date int, + added_by blob not null, -- ID of the user that added it created_at int not null default (unixepoch()), - last_updated int not null default (unixepoch()) + last_updated int not null default (unixepoch()), + foreign key (added_by) references witches (id) ); -- table of what people want to watch @@ -68,6 +70,6 @@ create table if not exists watch_notes ( -- indices, not needed for covens create index if not exists witch_dex on witches ( username, email ); -create index if not exists watch_dex on watches ( title, runtime, release_date ); +create index if not exists watch_dex on watches ( title, length, release_date, added_by ); create index if not exists ww_dex on witch_watch ( witch, watch, public ); create index if not exists note_dex on watch_notes ( witch, watch, public ); diff --git a/src/lib.rs b/src/lib.rs index 6638c22..e4b88d5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,6 +17,7 @@ pub mod signup; pub(crate) mod templates; pub mod users; pub(crate) mod util; +pub mod watches; #[cfg(test)] pub mod test_utils; diff --git a/src/main.rs b/src/main.rs index 7418799..5aa68c4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,10 +25,10 @@ async fn main() { let app = witch_watch::app(pool, &secret).await; - let addr = ([127, 0, 0, 1], 3000); + let addr: SocketAddr = ([127, 0, 0, 1], 3000).into(); tracing::debug!("binding to {addr:?}"); - axum::Server::bind(&SocketAddr::from(addr)) + axum::Server::bind(&addr) .serve(app.into_make_service()) .await .unwrap(); diff --git a/src/watches/handlers.rs b/src/watches/handlers.rs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/watches/handlers.rs @@ -0,0 +1 @@ + diff --git a/src/watches/mod.rs b/src/watches/mod.rs new file mode 100644 index 0000000..62ebe09 --- /dev/null +++ b/src/watches/mod.rs @@ -0,0 +1,74 @@ +use serde::{Deserialize, Serialize}; +use uuid::Uuid; + +mod handlers; + +pub use handlers::*; + +#[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 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, + pub length: Option, + pub release_date: Option, + 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() + } + } +}