use actix_web::{HttpResponse, get, web};
use serde_json::json;
use crate::AppState;
#[get("/")]
pub async fn root(app_state: web::Data<AppState>) -> HttpResponse {
let athena_deadpool = if app_state.pg_registry.list_clients().is_empty() {
"offline"
} else {
"online"
};
let body: serde_json::Value = json!({
"message": "athena is online",
"version": env!("CARGO_PKG_VERSION"),
"athena_api": "online",
"athena_deadpool": athena_deadpool,
"athena_scylladb": "online",
"cargo_toml_version": env!("CARGO_PKG_VERSION"),
"routes": [
{ "path": "/", "methods": ["GET"], "summary": "API root and route listing" },
{ "path": "/ping", "methods": ["GET"], "summary": "Health check" },
{ "path": "/clients", "methods": ["GET"], "summary": "List Athena clients (protected)" },
{ "path": "/schema/clients", "methods": ["GET"], "summary": "List Postgres clients" },
{ "path": "/schema/tables", "methods": ["GET"], "summary": "List tables" },
{ "path": "/schema/columns", "methods": ["GET"], "summary": "List columns" },
{ "path": "/schema/migrations", "methods": ["GET"], "summary": "List schema migrations (graceful fallback when table absent)" },
{ "path": "/router/registry", "methods": ["GET"], "summary": "Athena router registry" },
{ "path": "/registry", "methods": ["GET"], "summary": "API registry" },
{ "path": "/gateway/fetch", "methods": ["POST"], "summary": "Fetch data" },
{ "path": "/gateway/update", "methods": ["POST"], "summary": "Update data" },
{ "path": "/gateway/insert", "methods": ["PUT"], "summary": "Insert data" },
{ "path": "/gateway/delete", "methods": ["DELETE"], "summary": "Delete data" },
{ "path": "/gateway/query", "methods": ["POST"], "summary": "Execute SQL" },
{ "path": "/query/sql", "methods": ["POST"], "summary": "Execute SQL via driver" },
{ "path": "/pipelines", "methods": ["POST"], "summary": "Run pipeline" },
{ "path": "/admin/api-keys", "methods": ["GET", "POST"], "summary": "Manage API keys" },
{ "path": "/admin/api-keys/{id}", "methods": ["PATCH", "DELETE"], "summary": "Update or delete an API key" },
{ "path": "/admin/api-key-rights", "methods": ["GET", "POST"], "summary": "Manage API key rights" },
{ "path": "/admin/api-key-rights/{id}", "methods": ["PATCH", "DELETE"], "summary": "Update or delete an API key right" },
{ "path": "/admin/api-key-config", "methods": ["GET", "PUT"], "summary": "Manage global API key enforcement" },
{ "path": "/admin/api-key-clients", "methods": ["GET"], "summary": "List per-client API key enforcement" },
{ "path": "/admin/api-key-clients/{client_name}", "methods": ["PUT", "DELETE"], "summary": "Manage per-client API key enforcement" },
{ "path": "/admin/clients", "methods": ["GET", "POST"], "summary": "Manage Athena client catalog" },
{ "path": "/admin/clients/{client_name}", "methods": ["PATCH", "DELETE"], "summary": "Update or delete an Athena client" },
{ "path": "/admin/clients/{client_name}/freeze", "methods": ["PUT"], "summary": "Freeze or unfreeze an Athena client" },
{ "path": "/admin/clients/statistics", "methods": ["GET"], "summary": "List Athena client statistics" },
{ "path": "/admin/clients/statistics/refresh", "methods": ["POST"], "summary": "Rebuild Athena client statistics from logs" },
{ "path": "/admin/clients/{client_name}/statistics", "methods": ["GET"], "summary": "Inspect Athena client statistics" },
{ "path": "/openapi.yaml", "methods": ["GET"], "summary": "OpenAPI spec" },
{ "path": "/openapi-wss.yaml", "methods": ["GET"], "summary": "WebSocket OpenAPI spec" },
{ "path": "/wss/info", "methods": ["GET"], "summary": "WebSocket gateway contract" },
{ "path": "/docs", "methods": ["GET"], "summary": "Documentation redirect" },
],
});
HttpResponse::Ok()
.content_type("application/json")
.json(body)
}
#[get("/ping")]
pub async fn ping() -> HttpResponse {
HttpResponse::Ok()
.content_type("text/plain; charset=utf-8")
.body("pong")
}