From 9dd94875c6c7a4c25c935d344de96174d5ef6516 Mon Sep 17 00:00:00 2001 From: Michael Robbins Date: Tue, 2 Apr 2024 23:27:28 +1100 Subject: [PATCH] Remove category_id from each item --- src/filesystem.rs | 8 +++----- src/tasks.rs | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/filesystem.rs b/src/filesystem.rs index 04828e1..bc01a17 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -9,22 +9,20 @@ pub fn build_path(base_path: &String, category_path: &String) -> PathBuf { #[derive(Debug, Serialize, Deserialize, Clone)] pub(crate) struct CategoryItem { - category: String, id: String, name: String, items: Vec, } -fn entry_to_item(entry: fs::DirEntry, category_id: String) -> CategoryItem { +fn entry_to_item(entry: fs::DirEntry) -> CategoryItem { CategoryItem { - category: category_id.clone(), id: entry.file_name().into_string().unwrap(), name: entry.file_name().into_string().unwrap(), items: vec![], } } -pub fn get_category_items(category_path: PathBuf, category_id: String) -> Vec { +pub fn get_category_items(category_path: PathBuf) -> Vec { match fs::read_dir(category_path) { Err(why) => { println!("ERROR: Unable to list path: {:?}", why.kind()); @@ -32,7 +30,7 @@ pub fn get_category_items(category_path: PathBuf, category_id: String) -> Vec paths .filter(|i| i.as_ref().unwrap().file_type().unwrap().is_dir()) - .map(|i| entry_to_item(i.unwrap(), category_id.clone())) + .map(|i| entry_to_item(i.unwrap())) .collect(), } } diff --git a/src/tasks.rs b/src/tasks.rs index 5202a70..8542217 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -48,7 +48,7 @@ pub async fn category_info( StatusCode::OK, Json(CategoryInfoResponse { name: category.name.clone(), - items: filesystem::get_category_items(category_path, category.id.clone()), + items: filesystem::get_category_items(category_path), }), ) .into_response() @@ -56,7 +56,7 @@ pub async fn category_info( None => ( StatusCode::NOT_FOUND, Json(CategoryInfoNotFoundResponse { - message: "Category ID not found".to_string(), + message: !fmt("Category ID {} not found", category_id), }), ) .into_response(),