use axum::Json; use axum::extract::State; use crate::error::ApiResult; use crate::models::health::{HealthResponse, ReadyResponse}; use crate::state::AppState; /// Liveness probe. Process is up. #[utoipa::path( get, path = "/health/live", tag = "health", responses( (status = 200, description = "Process is running", body = HealthResponse) ) )] pub async fn live(State(state): State) -> Json { Json(HealthResponse { status: "ok", service: state.config().app.name.clone() }) } /// Readiness probe. Database is reachable. #[utoipa::path( get, path = "/health/ready", tag = "health", responses( (status = 200, description = "Database is reachable", body = ReadyResponse), (status = 500, description = "Database is unreachable", body = crate::error::ErrorBody) ) )] pub async fn ready(State(state): State) -> ApiResult> { sqlx::query_scalar::<_, i32>("SELECT 1").fetch_one(state.db()).await?; Ok(Json(ReadyResponse { status: "ok", database: "up" })) }