diff --git a/migrations/20240116054243_watches_and_quests.up.sql b/migrations/20240116054243_watches_and_quests.up.sql index bf95097..76fa7b0 100644 --- a/migrations/20240116054243_watches_and_quests.up.sql +++ b/migrations/20240116054243_watches_and_quests.up.sql @@ -5,7 +5,7 @@ create table if not exists watches ( title text not null, metadata_url text, -- possible url for imdb or other metadata-esque site to show the user length int, - release_date datetime, + release_date date, added_by blob not null, -- ID of the user that added it last_updated datetime not null default CURRENT_TIMESTAMP, foreign key (added_by) references users (id) @@ -26,7 +26,7 @@ create table if not exists watch_quests ( priority int, -- 1-5 how much do you want to watch it public boolean not null default true, watched boolean not null default false, - when_watched int, + when_watched datetime, created_at datetime not null default CURRENT_TIMESTAMP, last_updated datetime not null default CURRENT_TIMESTAMP, foreign key (user) references users (id) on delete cascade on update no action, diff --git a/migrations/20240116054253_stars_and_credits.up.sql b/migrations/20240116054253_stars_and_credits.up.sql index d685661..7590513 100644 --- a/migrations/20240116054253_stars_and_credits.up.sql +++ b/migrations/20240116054253_stars_and_credits.up.sql @@ -2,8 +2,8 @@ create table if not exists stars ( id blob not null primary key default (julid_new()), name text not null, metadata_url text, - born int, - died int + born date, + died date ); create index if not exists stars_name_dex on stars (lower(name)); diff --git a/src/imdb_utils.rs b/src/imdb_utils.rs index 8590146..99f4d87 100644 --- a/src/imdb_utils.rs +++ b/src/imdb_utils.rs @@ -3,7 +3,6 @@ use sqlx::{Connection, Sqlite, SqlitePool}; use crate::{ import_utils::{insert_credit, insert_star, insert_watch}, - misc_util::year_to_epoch, Credit, ShowKind, Star, Watch, }; @@ -25,7 +24,7 @@ impl From for Watch { Watch { id: OMEGA_ID, // this is ignored by the inserter title: value.title, - release_date: year_to_epoch(value.year.as_deref()), + release_date: value.year, length: value.length.and_then(|v| v.parse::().ok()), kind: ShowKind::Movie, metadata_url: Some(format!("https://imdb.com/title/{}/", &value.id)), @@ -39,7 +38,7 @@ impl From<&ImportImdbMovie> for Watch { Watch { id: OMEGA_ID, title: value.title.to_string(), - release_date: year_to_epoch(value.year.as_deref()), + release_date: value.year.clone(), length: value.length.as_ref().and_then(|v| v.parse::().ok()), kind: ShowKind::Movie, metadata_url: Some(format!("https://imdb.com/title/{}/", value.id)), @@ -66,8 +65,8 @@ impl From<&ImdbStar> for Star { Self { name: value.name.clone(), metadata_url, - born: year_to_epoch(value.born.as_deref()), - died: year_to_epoch(value.died.as_deref()), + born: value.born.clone(), + died: value.died.clone(), ..Default::default() } } diff --git a/src/import_utils.rs b/src/import_utils.rs index 920fc7d..808b711 100644 --- a/src/import_utils.rs +++ b/src/import_utils.rs @@ -31,8 +31,8 @@ pub async fn insert_star(star: &Star, db: &mut SqliteConnection) -> Julid { sqlx::query_scalar(q) .bind(&star.name) .bind(&star.metadata_url) - .bind(star.born) - .bind(star.died) + .bind(&star.born) + .bind(&star.died) .fetch_one(db) .await .unwrap() diff --git a/src/misc_util.rs b/src/misc_util.rs index 21dd34e..99e9f2c 100644 --- a/src/misc_util.rs +++ b/src/misc_util.rs @@ -35,17 +35,3 @@ where .map(Some), } } - -/// Convert a stringy number like "1999" to a 64-bit signed unix epoch-based -/// timestamp -pub fn year_to_epoch(year: Option<&str>) -> Option { - year? - .trim() - .parse::() - .map(|year| { - let years = (year - 1970) as f32; - let days = (years * 365.2425) as i64; - days * 24 * 60 * 60 - }) - .ok() -} diff --git a/src/search.rs b/src/search.rs index d8d4555..d17e2f4 100644 --- a/src/search.rs +++ b/src/search.rs @@ -32,7 +32,7 @@ pub struct SearchQuery { #[serde(default, deserialize_with = "empty_string_as_none")] pub kind: Option, #[serde(default, deserialize_with = "empty_string_as_none")] - pub year: Option, + pub year: Option, } pub async fn get_search_watch( diff --git a/src/stars.rs b/src/stars.rs index 1593b08..89bd338 100644 --- a/src/stars.rs +++ b/src/stars.rs @@ -7,8 +7,8 @@ pub struct Star { pub id: Julid, pub name: String, pub metadata_url: Option, - pub born: Option, - pub died: Option, + pub born: Option, + pub died: Option, } #[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize, FromRow)] diff --git a/src/watches/handlers.rs b/src/watches/handlers.rs index 6bcf0c7..3519c78 100644 --- a/src/watches/handlers.rs +++ b/src/watches/handlers.rs @@ -10,8 +10,7 @@ use sqlx::{query, query_as, query_scalar, SqlitePool}; use super::templates::{AddNewWatchPage, AddWatchButton, GetWatchPage}; use crate::{ - misc_util::{empty_string_as_none, year_to_epoch}, - AuthSession, MyWatchesPage, ShowKind, Watch, WatchQuest, + misc_util::empty_string_as_none, AuthSession, MyWatchesPage, ShowKind, Watch, WatchQuest, }; //-************************************************************************ @@ -99,12 +98,11 @@ pub async fn post_add_new_watch( ) -> Result { if let Some(user) = auth.user { { - let release_date = year_to_epoch(form.year.as_deref()); let watch = Watch { title: form.title, kind: form.kind, metadata_url: form.metadata_url, - release_date, + release_date: form.year, added_by: user.id, ..Default::default() }; @@ -132,7 +130,7 @@ async fn add_new_watch_impl(db_pool: &SqlitePool, watch: &Watch) -> Result, pub length: Option, - pub release_date: Option, + pub release_date: Option, pub added_by: Julid, // this shouldn't be exposed to randos in the application } -impl Watch { - pub fn year(&self) -> Option { - if let Some(year) = self.release_date { - let date = chrono::NaiveDateTime::from_timestamp_opt(year, 0)?; - let year = format!("{}", date.format("%Y")); - Some(year) - } else { - None - } - } -} - //-************************************************************************ /// Something a user wants to watch //-************************************************************************ diff --git a/templates/get_watch_page.html b/templates/get_watch_page.html index bf7d60e..b608abf 100644 --- a/templates/get_watch_page.html +++ b/templates/get_watch_page.html @@ -12,7 +12,7 @@ {% when Some with (watch) %}
- {{watch.title}} -- {% call m::get_or_default(watch.year(), "when??") %} + {{watch.title}} -- {% call m::get_or_default(watch.release_date, "when??") %}
{% else %} diff --git a/templates/my_watches_page.html b/templates/my_watches_page.html index aa42ec6..96ad30d 100644 --- a/templates/my_watches_page.html +++ b/templates/my_watches_page.html @@ -28,7 +28,8 @@
    {% for watch in watches %} -
  • {{watch.title}} -- {% call m::get_or_default(watch.year(), "when??") %} +
  • {{watch.title}} -- {% call m::get_or_default(watch.release_date, "when??") + %}
  • {% endfor %}
diff --git a/templates/watch-search-result.html b/templates/watch-search-result.html index cdf8369..e94e884 100644 --- a/templates/watch-search-result.html +++ b/templates/watch-search-result.html @@ -9,7 +9,7 @@ {{res.kind}} - {% call m::get_or_default(res.year(), "when??") -%} + {% call m::get_or_default(res.release_date, "when??") -%}