use crate::{
error::{HttpCommonError, HttpErrorResponse, HttpResult},
middleware::tenant::{TenantDb, TenantParams},
models::{document_box::DocumentBoxScope, task::HttpTaskError},
};
use axum::{Json, extract::Path};
use docbox_core::database::models::tasks::{Task, TaskId};
pub const TASK_TAG: &str = "Task";
#[utoipa::path(
get,
operation_id = "task_get",
tag = TASK_TAG,
path = "/box/{scope}/task/{task_id}",
responses(
(status = 200, description = "Task found successfully", body = Task),
(status = 404, description = "Task not found", body = HttpErrorResponse),
(status = 500, description = "Internal server error", body = HttpErrorResponse)
),
params(
("scope" = String, Path, description = "Scope the task is within"),
("task_id" = Uuid, Path, description = "ID of the task to query"),
TenantParams
)
)]
#[tracing::instrument(skip_all, fields(%scope, %task_id))]
pub async fn get(
TenantDb(db): TenantDb,
Path((scope, task_id)): Path<(DocumentBoxScope, TaskId)>,
) -> HttpResult<Task> {
let DocumentBoxScope(scope) = scope;
let task = Task::find(&db, task_id, &scope)
.await
.map_err(|error| {
tracing::error!(?scope, ?task_id, ?error, "failed to query task");
HttpCommonError::ServerError
})?
.ok_or(HttpTaskError::UnknownTask)?;
Ok(Json(task))
}