video updating and creation now works
Some checks are pending
/ test (push) Waiting to run

This commit is contained in:
Chris Cochrun 2025-09-25 13:25:28 -05:00
parent 5cb53cbe72
commit 08a140054e
2 changed files with 61 additions and 6 deletions

View file

@ -245,6 +245,49 @@ pub async fn update_video_in_db(
.to_str()
.map(std::string::ToString::to_string)
.unwrap_or_default();
let mut db = db.detach();
let id = video.id.clone();
if let Err(e) = query!("SELECT id FROM videos where id = $1", id)
.fetch_one(&mut db)
.await
{
if let Ok(ids) =
query!("SELECT id FROM videos").fetch_all(&mut db).await
{
let Some(mut max) = ids.iter().map(|r| r.id).max() else {
return Err(miette::miette!("cannot find max id"));
};
debug!(?e, "Video not found");
max += 1;
let result = query!(
r#"INSERT into videos VALUES($1, $2, $3, $4, $5, $6)"#,
max,
video.title,
path,
video.start_time,
video.end_time,
video.looping,
)
.execute(&mut db)
.await
.into_diagnostic();
return match result {
Ok(_) => {
debug!("should have been updated");
Ok(())
}
Err(e) => {
error! {?e};
Err(e)
}
};
} else {
return Err(miette::miette!("cannot find ids"));
}
};
debug!(?video, "should be been updated");
let result = query!(
r#"UPDATE videos SET title = $2, file_path = $3, start_time = $4, end_time = $5, loop = $6 WHERE id = $1"#,
video.id,
@ -254,11 +297,14 @@ pub async fn update_video_in_db(
video.end_time,
video.looping,
)
.execute(&mut db.detach())
.execute(&mut db)
.await.into_diagnostic();
match result {
Ok(_) => Ok(()),
Ok(_) => {
debug!("should have been updated");
Ok(())
}
Err(e) => {
error! {?e};
Err(e)