fix: remove unused delete_item handler and add accessors for unused fields
Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
@@ -161,54 +161,6 @@ pub async fn handle_post_item(
|
||||
Ok(Json(response))
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
delete,
|
||||
path = "/api/item/{item_id}",
|
||||
operation_id = "delete_item",
|
||||
summary = "Delete stored item",
|
||||
description = "Permanently delete an item and all its associated metadata, tags, and stored content. This operation cannot be undone. The item's compressed data file and all database records will be removed.",
|
||||
responses(
|
||||
(status = 200, description = "Successfully deleted item and all associated metadata, tags, and content"),
|
||||
(status = 400, description = "Bad request - Invalid item ID (must be a positive integer)"),
|
||||
(status = 401, description = "Unauthorized - Invalid or missing authentication credentials"),
|
||||
(status = 404, description = "Item not found - No item exists with the specified ID"),
|
||||
(status = 500, description = "Internal server error - Failed to delete item due to database or filesystem error")
|
||||
),
|
||||
params(
|
||||
("item_id" = i64, Path, description = "Unique identifier of the item to delete (must be a positive integer)")
|
||||
),
|
||||
security(
|
||||
("bearerAuth" = [])
|
||||
),
|
||||
tag = "item"
|
||||
)]
|
||||
pub async fn handle_delete_item(
|
||||
State(state): State<AppState>,
|
||||
Path(item_id): Path<i64>,
|
||||
) -> Result<Json<ApiResponse<()>>, StatusCode> {
|
||||
// Validate that item ID is positive to prevent path traversal issues
|
||||
if item_id <= 0 {
|
||||
return Err(StatusCode::BAD_REQUEST);
|
||||
}
|
||||
|
||||
let mut conn = state.db.lock().await;
|
||||
|
||||
if let Some(item) = db::get_item(&mut *conn, item_id).map_err(|e| {
|
||||
warn!("Failed to get item {} for deletion: {}", item_id, e);
|
||||
StatusCode::INTERNAL_SERVER_ERROR
|
||||
})? {
|
||||
db::delete_item(&mut *conn, item).map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
||||
|
||||
let response = ApiResponse::<()> {
|
||||
success: true,
|
||||
data: None,
|
||||
error: None,
|
||||
};
|
||||
Ok(Json(response))
|
||||
} else {
|
||||
Err(StatusCode::NOT_FOUND)
|
||||
}
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
get,
|
||||
|
||||
@@ -32,6 +32,16 @@ pub struct AppState {
|
||||
pub password_hash: Option<String>,
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
pub fn password(&self) -> Option<&String> {
|
||||
self.password.as_ref()
|
||||
}
|
||||
|
||||
pub fn password_hash(&self) -> Option<&String> {
|
||||
self.password_hash.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, ToSchema)]
|
||||
#[schema(description = "Standard API response wrapper containing success status, data payload, and error information")]
|
||||
pub struct ApiResponse<T> {
|
||||
|
||||
Reference in New Issue
Block a user