use crate::web::handlers;
use crate::web::openapi::ApiDoc;
use crate::web::state::AppState;
use axum::routing::{delete, get, patch, post};
use axum::Router;
use tasker_shared::types::resources::{Action, Resource};
use tasker_shared::web::authorize;
use utoipa::OpenApi;
use utoipa_swagger_ui::SwaggerUi;
pub fn api_v1_routes() -> Router<AppState> {
Router::new()
.route(
"/tasks",
post(authorize(
Resource::Tasks,
Action::Create,
handlers::tasks::create_task,
)),
)
.route(
"/tasks",
get(authorize(
Resource::Tasks,
Action::List,
handlers::tasks::list_tasks,
)),
)
.route(
"/tasks/{uuid}",
get(authorize(
Resource::Tasks,
Action::Read,
handlers::tasks::get_task,
)),
)
.route(
"/tasks/{uuid}",
delete(authorize(
Resource::Tasks,
Action::Cancel,
handlers::tasks::cancel_task,
)),
)
.route(
"/tasks/{uuid}/workflow_steps",
get(authorize(
Resource::Steps,
Action::List,
handlers::steps::list_task_steps,
)),
)
.route(
"/tasks/{uuid}/workflow_steps/{step_uuid}",
get(authorize(
Resource::Steps,
Action::Read,
handlers::steps::get_step,
)),
)
.route(
"/tasks/{uuid}/workflow_steps/{step_uuid}",
patch(authorize(
Resource::Steps,
Action::Resolve,
handlers::steps::resolve_step_manually,
)),
)
.route(
"/tasks/{uuid}/workflow_steps/{step_uuid}/audit",
get(authorize(
Resource::Steps,
Action::Read,
handlers::steps::get_step_audit,
)),
)
.route(
"/templates",
get(authorize(
Resource::Templates,
Action::List,
handlers::templates::list_templates,
)),
)
.route(
"/templates/{namespace}/{name}/{version}",
get(authorize(
Resource::Templates,
Action::Read,
handlers::templates::get_template,
)),
)
.route(
"/analytics/performance",
get(authorize(
Resource::System,
Action::AnalyticsRead,
handlers::analytics::get_performance_metrics,
)),
)
.route(
"/analytics/bottlenecks",
get(authorize(
Resource::System,
Action::AnalyticsRead,
handlers::analytics::get_bottlenecks,
)),
)
.route(
"/dlq",
get(authorize(
Resource::Dlq,
Action::List,
handlers::dlq::list_dlq_entries,
)),
)
.route(
"/dlq/task/{task_uuid}",
get(authorize(
Resource::Dlq,
Action::Read,
handlers::dlq::get_dlq_entry,
)),
)
.route(
"/dlq/entry/{dlq_entry_uuid}",
patch(authorize(
Resource::Dlq,
Action::Update,
handlers::dlq::update_dlq_investigation,
)),
)
.route(
"/dlq/stats",
get(authorize(
Resource::Dlq,
Action::Stats,
handlers::dlq::get_dlq_stats,
)),
)
.route(
"/dlq/investigation-queue",
get(authorize(
Resource::Dlq,
Action::Read,
handlers::dlq::get_investigation_queue,
)),
)
.route(
"/dlq/staleness",
get(authorize(
Resource::Dlq,
Action::Read,
handlers::dlq::get_staleness_monitoring,
)),
)
}
pub fn health_routes() -> Router<AppState> {
Router::new()
.route("/health", get(handlers::health::basic_health))
.route("/health/ready", get(handlers::health::readiness_probe))
.route("/health/live", get(handlers::health::liveness_probe))
.route("/health/detailed", get(handlers::health::detailed_health))
.route("/metrics", get(handlers::health::prometheus_metrics))
}
pub fn config_routes() -> Router<AppState> {
Router::new().route(
"/config",
get(authorize(
Resource::System,
Action::ConfigRead,
handlers::config::get_config,
)),
)
}
#[cfg(feature = "web-api")]
pub fn docs_routes() -> Router<AppState> {
SwaggerUi::new("/api-docs/ui")
.url("/api-docs/openapi.json", ApiDoc::openapi())
.into()
}