use axum::{Json, extract::State};
use serde::{Deserialize, Serialize};
use crate::routes::graphql::app_state::AppState;
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct AdminHealthResponse {
pub uptime_secs: u64,
pub version: String,
pub pool_active: Option<u32>,
pub pool_idle: Option<u32>,
pub pool_max: Option<u32>,
pub cache_hit_rate: Option<f64>,
pub cache_entries: Option<u64>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct AdminSchemaResponse {
pub schema: serde_json::Value,
}
#[must_use]
pub fn extract_bearer_token(auth_header: Option<&str>) -> Option<&str> {
let header = auth_header?;
header.strip_prefix("Bearer ")
}
pub async fn schema_handler(State(state): State<AppState>) -> impl axum::response::IntoResponse {
let schema = state.executor.load().schema().clone();
let value = serde_json::to_value(&schema).unwrap_or(serde_json::Value::Null);
Json(AdminSchemaResponse { schema: value })
}
pub async fn health_handler(State(state): State<AppState>) -> impl axum::response::IntoResponse {
let uptime_secs = state.started_at.elapsed().as_secs();
Json(AdminHealthResponse {
uptime_secs,
version: env!("CARGO_PKG_VERSION").to_string(),
pool_active: None,
pool_idle: None,
pool_max: None,
cache_hit_rate: None,
cache_entries: None,
})
}