update todo

This commit is contained in:
Chris Cochrun 2024-10-09 13:39:40 -05:00
parent 362a31581d
commit ba51c56169
2 changed files with 20 additions and 8 deletions

View file

@ -1,10 +1,12 @@
use std::path::PathBuf;
use sqlx::query_as;
use tracing::error;
use crate::model::Model;
use serde::{Deserialize, Serialize};
use sqlx::query_as;
use std::path::PathBuf;
use tracing::error;
#[derive(Clone, Debug, Default, PartialEq)]
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct Image {
pub id: i32,
pub title: String,
pub path: PathBuf,
}
@ -13,14 +15,14 @@ impl Model<Image> {
pub fn load_from_db(&mut self) {
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
let result = query_as!(Image, r#"SELECT title as "title!", filePath as "path!" from images"#).fetch_all(&mut self.db).await;
let result = query_as!(Image, r#"SELECT title as "title!", filePath as "path!", id as "id: i32" from images"#).fetch_all(&mut self.db).await;
match result {
Ok(v) => {
for image in v.into_iter() {
let _ = self.add_item(image);
}
}
Err(e) => error!("There was an error in converting songs: {e}"),
Err(e) => error!("There was an error in converting images: {e}"),
}
});
}
@ -60,9 +62,16 @@ mod test {
match result {
Ok(_) => {
assert_eq!(&image, image_model.get_item(0).unwrap());
assert_ne!(&new_image, image_model.get_item(0).unwrap());
assert_ne!(
&new_image,
image_model.get_item(0).unwrap()
);
}
Err(e) => assert!(false, "There was an error adding the image: {:?}", e),
Err(e) => assert!(
false,
"There was an error adding the image: {:?}",
e
),
}
}
}