adds Watches struct
This commit is contained in:
parent
edaf9e50f3
commit
1a4ffaa99d
5 changed files with 84 additions and 6 deletions
|
@ -20,11 +20,13 @@ create table if not exists watches (
|
||||||
id blob not null primary key,
|
id blob not null primary key,
|
||||||
typ int not null, -- enum for movie or tv show or whatev
|
typ int not null, -- enum for movie or tv show or whatev
|
||||||
title text not null,
|
title text not null,
|
||||||
imdb text, -- possible url for imdb or other metadata-esque site to show the user
|
metadata_url text, -- possible url for imdb or other metadata-esque site to show the user
|
||||||
runtime int,
|
length int,
|
||||||
release_date int,
|
release_date int,
|
||||||
|
added_by blob not null, -- ID of the user that added it
|
||||||
created_at int not null default (unixepoch()),
|
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
|
-- table of what people want to watch
|
||||||
|
@ -68,6 +70,6 @@ create table if not exists watch_notes (
|
||||||
|
|
||||||
-- indices, not needed for covens
|
-- indices, not needed for covens
|
||||||
create index if not exists witch_dex on witches ( username, email );
|
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 ww_dex on witch_watch ( witch, watch, public );
|
||||||
create index if not exists note_dex on watch_notes ( witch, watch, public );
|
create index if not exists note_dex on watch_notes ( witch, watch, public );
|
||||||
|
|
|
@ -17,6 +17,7 @@ pub mod signup;
|
||||||
pub(crate) mod templates;
|
pub(crate) mod templates;
|
||||||
pub mod users;
|
pub mod users;
|
||||||
pub(crate) mod util;
|
pub(crate) mod util;
|
||||||
|
pub mod watches;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub mod test_utils;
|
pub mod test_utils;
|
||||||
|
|
|
@ -25,10 +25,10 @@ async fn main() {
|
||||||
|
|
||||||
let app = witch_watch::app(pool, &secret).await;
|
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:?}");
|
tracing::debug!("binding to {addr:?}");
|
||||||
|
|
||||||
axum::Server::bind(&SocketAddr::from(addr))
|
axum::Server::bind(&addr)
|
||||||
.serve(app.into_make_service())
|
.serve(app.into_make_service())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
1
src/watches/handlers.rs
Normal file
1
src/watches/handlers.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
74
src/watches/mod.rs
Normal file
74
src/watches/mod.rs
Normal file
|
@ -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<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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue