refactor(server): extract locate_case_or_404 helper
Consolidate 5 instances of "locate_case + warn! + 404-return" boilerplate (case_actions.rs x4, user_web.rs x1) into a single pub(crate) helper in user_web.rs. The helper takes &CaseId (no String allocation at call sites) plus a context tag that becomes a structured-log field instead of being baked into the message. bulk.rs keeps using the underlying locate_case because its miss semantics differ (silent skip, not 404).
This commit is contained in:
@@ -20,7 +20,7 @@ use crate::case_id::CaseIdPath;
|
||||
use crate::config::Config;
|
||||
use crate::error::AppError;
|
||||
use crate::paths::{read_delete_marker, write_delete_marker, DeleteMarker, DELETE_MARKER};
|
||||
use crate::routes::user_web::locate_case;
|
||||
use crate::routes::user_web::locate_case_or_404;
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "document.html")]
|
||||
@@ -49,13 +49,7 @@ pub async fn handle_analyze_case(
|
||||
}
|
||||
|
||||
let user_root = config.data_path.join(&user.slug);
|
||||
let case_dir = match locate_case(&user_root, &case_id.to_string()).await {
|
||||
Some(p) => p,
|
||||
None => {
|
||||
warn!(slug = %user.slug, case_id = %case_id, "analyze: case not found");
|
||||
return Err(AppError::NotFound("Case not found".into()));
|
||||
}
|
||||
};
|
||||
let case_dir = locate_case_or_404(&user_root, &case_id, &user.slug, "analyze").await?;
|
||||
|
||||
// Re-analyze: delete the existing document first so the UI stops showing
|
||||
// the stale "ausgewertet" state while the worker re-computes. Ignore
|
||||
@@ -103,13 +97,7 @@ pub async fn handle_document_view(
|
||||
CaseIdPath(case_id): CaseIdPath,
|
||||
) -> Result<Html<String>, AppError> {
|
||||
let user_root = config.data_path.join(&user.slug);
|
||||
let case_dir = match locate_case(&user_root, &case_id.to_string()).await {
|
||||
Some(p) => p,
|
||||
None => {
|
||||
warn!(slug = %user.slug, case_id = %case_id, "document view: case not found");
|
||||
return Err(AppError::NotFound("Case not found".into()));
|
||||
}
|
||||
};
|
||||
let case_dir = locate_case_or_404(&user_root, &case_id, &user.slug, "document view").await?;
|
||||
|
||||
let md = read_document(&case_dir)
|
||||
.await
|
||||
@@ -272,13 +260,7 @@ pub async fn handle_delete_case(
|
||||
CaseIdPath(case_id): CaseIdPath,
|
||||
) -> Result<Redirect, AppError> {
|
||||
let user_root = config.data_path.join(&user.slug);
|
||||
let case_dir = match locate_case(&user_root, &case_id.to_string()).await {
|
||||
Some(p) => p,
|
||||
None => {
|
||||
warn!(slug = %user.slug, case_id = %case_id, "delete: case not found");
|
||||
return Err(AppError::NotFound("Case not found".into()));
|
||||
}
|
||||
};
|
||||
let case_dir = locate_case_or_404(&user_root, &case_id, &user.slug, "delete").await?;
|
||||
|
||||
let marker = DeleteMarker {
|
||||
batch: uuid::Uuid::new_v4(),
|
||||
@@ -313,13 +295,7 @@ pub async fn handle_reset_case(
|
||||
}
|
||||
|
||||
let user_root = config.data_path.join(&user.slug);
|
||||
let case_dir = match locate_case(&user_root, &case_id.to_string()).await {
|
||||
Some(p) => p,
|
||||
None => {
|
||||
warn!(slug = %user.slug, case_id = %case_id, "reset: case not found");
|
||||
return Err(AppError::NotFound("Case not found".into()));
|
||||
}
|
||||
};
|
||||
let case_dir = locate_case_or_404(&user_root, &case_id, &user.slug, "reset").await?;
|
||||
|
||||
reset_case_artefacts(&case_dir)
|
||||
.await
|
||||
|
||||
Reference in New Issue
Block a user