feat: implement core services and refactor modes
Co-authored-by: aider (openai/andrew/openrouter/google/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
use anyhow::{Context, Result, anyhow};
|
||||
use std::fs;
|
||||
use anyhow::{anyhow, Result};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::db;
|
||||
use crate::config;
|
||||
use clap::Command;
|
||||
use crate::core::item_service::ItemService;
|
||||
use clap::error::ErrorKind;
|
||||
use log::{debug, warn};
|
||||
use clap::Command;
|
||||
use log::warn;
|
||||
use rusqlite::Connection;
|
||||
|
||||
pub fn mode_delete(
|
||||
@@ -32,23 +31,17 @@ pub fn mode_delete(
|
||||
.exit();
|
||||
}
|
||||
|
||||
let item_service = ItemService::new(data_path);
|
||||
|
||||
for item_id in ids.iter() {
|
||||
if let Some(item) = db::get_item(conn, *item_id)? {
|
||||
debug!("MAIN: Found item {:?}", item);
|
||||
db::delete_item(conn, item)?;
|
||||
|
||||
// Validate that item ID is positive to prevent path traversal issues
|
||||
if *item_id <= 0 {
|
||||
return Err(anyhow!("Invalid item ID: {}", item_id));
|
||||
}
|
||||
|
||||
let mut item_path = data_path.clone();
|
||||
item_path.push(item_id.to_string());
|
||||
|
||||
fs::remove_file(&item_path)
|
||||
.context(anyhow!("Unable to remove item file {:?}", item_path))?;
|
||||
} else {
|
||||
warn!("Unable to find item {item_id} in database");
|
||||
match item_service.delete_item(conn, *item_id) {
|
||||
Ok(_) => {}
|
||||
Err(e) => match e {
|
||||
crate::core::error::CoreError::ItemNotFound(_) => {
|
||||
warn!("Unable to find item {item_id} in database");
|
||||
}
|
||||
_ => return Err(anyhow!(e).context(format!("Failed to delete item {}", item_id))),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user