diff --git a/src/core/images.rs b/src/core/images.rs index eca52c4..292b52a 100644 --- a/src/core/images.rs +++ b/src/core/images.rs @@ -168,6 +168,17 @@ impl Model { } } +pub async fn remove_from_db( + db: PoolConnection, + id: i32, +) -> Result<()> { + query!("DELETE FROM images WHERE id = $1", id) + .execute(&mut db.detach()) + .await + .into_diagnostic() + .map(|_| ()) +} + pub async fn update_image_in_db( image: Image, db: PoolConnection, diff --git a/src/core/presentations.rs b/src/core/presentations.rs index 1bae1bf..768e693 100644 --- a/src/core/presentations.rs +++ b/src/core/presentations.rs @@ -263,6 +263,17 @@ impl Model { } } +pub async fn remove_from_db( + db: PoolConnection, + id: i32, +) -> Result<()> { + query!("DELETE FROM presentations WHERE id = $1", id) + .execute(&mut db.detach()) + .await + .into_diagnostic() + .map(|_| ()) +} + pub async fn update_presentation_in_db( presentation: Presentation, db: PoolConnection, diff --git a/src/core/slide.rs b/src/core/slide.rs index def56f7..30bf847 100644 --- a/src/core/slide.rs +++ b/src/core/slide.rs @@ -181,7 +181,7 @@ impl TryFrom for Background { } } Err(e) => { - error!("Couldn't canonicalize: {e} {:?}", path); + // error!("Couldn't canonicalize: {e} {:?}", path); Err(ParseError::CannotCanonicalize) } } diff --git a/src/core/songs.rs b/src/core/songs.rs index eccaae9..feb9d65 100644 --- a/src/core/songs.rs +++ b/src/core/songs.rs @@ -407,19 +407,17 @@ impl Model { } } } +} - pub async fn remove_from_db( - &mut self, - db: &mut SqlitePool, - id: i32, - ) -> Result<()> { - let db = db.acquire().await.expect("probs"); - query!("delete from songs where id = $1", id) - .execute(&mut db.detach()) - .await - .into_diagnostic() - .map(|_| ()) - } +pub async fn remove_from_db( + db: PoolConnection, + id: i32, +) -> Result<()> { + query!("DELETE FROM songs WHERE id = $1", id) + .execute(&mut db.detach()) + .await + .into_diagnostic() + .map(|_| ()) } pub async fn update_song_in_db( diff --git a/src/core/videos.rs b/src/core/videos.rs index f31aa20..528088d 100644 --- a/src/core/videos.rs +++ b/src/core/videos.rs @@ -11,10 +11,10 @@ use crisp::types::{Keyword, Symbol, Value}; use miette::{IntoDiagnostic, Result}; use serde::{Deserialize, Serialize}; use sqlx::{ - Sqlite, SqliteConnection, SqlitePool, pool::PoolConnection, - query, query_as, + pool::PoolConnection, query, query_as, Sqlite, SqliteConnection, + SqlitePool, }; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use tracing::error; #[derive( @@ -35,6 +35,25 @@ impl From<&Video> for Value { } } +impl From for Video { + fn from(value: PathBuf) -> Self { + let title: String = value.file_name().map_or_else(|| "Video".into(), |filename| { + filename.to_str().unwrap_or("Video").into() + }); + Self { + title, + path: value, + ..Default::default() + } + } +} + +impl From<&Path> for Video { + fn from(value: &Path) -> Self { + Self::from(value.to_owned()) + } +} + impl Content for Video { fn title(&self) -> String { self.title.clone() @@ -205,6 +224,17 @@ impl Model