docbox_http/routes/
task.rs1use crate::{
6 error::{HttpCommonError, HttpErrorResponse, HttpResult},
7 middleware::tenant::{TenantDb, TenantParams},
8 models::{document_box::DocumentBoxScope, task::HttpTaskError},
9};
10use axum::{Json, extract::Path};
11use docbox_core::database::models::tasks::{Task, TaskId};
12
13pub const TASK_TAG: &str = "Task";
14
15#[utoipa::path(
20 get,
21 operation_id = "task_get",
22 tag = TASK_TAG,
23 path = "/box/{scope}/task/{task_id}",
24 responses(
25 (status = 200, description = "Task found successfully", body = Task),
26 (status = 404, description = "Task not found", body = HttpErrorResponse),
27 (status = 500, description = "Internal server error", body = HttpErrorResponse)
28 ),
29 params(
30 ("scope" = String, Path, description = "Scope the task is within"),
31 ("task_id" = Uuid, Path, description = "ID of the task to query"),
32 TenantParams
33 )
34)]
35#[tracing::instrument(skip_all, fields(%scope, %task_id))]
36pub async fn get(
37 TenantDb(db): TenantDb,
38 Path((scope, task_id)): Path<(DocumentBoxScope, TaskId)>,
39) -> HttpResult<Task> {
40 let DocumentBoxScope(scope) = scope;
41
42 let task = Task::find(&db, task_id, &scope)
43 .await
44 .map_err(|error| {
46 tracing::error!(?scope, ?task_id, ?error, "failed to query task");
47 HttpCommonError::ServerError
48 })?
49 .ok_or(HttpTaskError::UnknownTask)?;
51
52 Ok(Json(task))
53}