Skip to content

Commit

Permalink
Remove category_id from each item
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-robbins committed Apr 2, 2024
1 parent 4f4d6d0 commit 9dd9487
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
8 changes: 3 additions & 5 deletions src/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,28 @@ 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<CategoryItem>,
}

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<CategoryItem> {
pub fn get_category_items(category_path: PathBuf) -> Vec<CategoryItem> {
match fs::read_dir(category_path) {
Err(why) => {
println!("ERROR: Unable to list path: {:?}", why.kind());
vec![]
}
Ok(paths) => 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(),
}
}
4 changes: 2 additions & 2 deletions src/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ 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()
}
None => (
StatusCode::NOT_FOUND,
Json(CategoryInfoNotFoundResponse {
message: "Category ID not found".to_string(),
message: !fmt("Category ID {} not found", category_id),
}),
)
.into_response(),
Expand Down

0 comments on commit 9dd9487

Please sign in to comment.