use axum::{extract::State, Json};
use serde::Serialize;
use crate::state::AppState;
#[derive(Serialize)]
pub struct HealthResponse {
pub status: String,
pub version: String,
}
#[derive(Serialize)]
pub struct ReadyResponse {
pub status: String,
pub sessions: usize,
}
pub async fn health() -> Json<HealthResponse> {
Json(HealthResponse {
status: "ok".to_string(),
version: env!("CARGO_PKG_VERSION").to_string(),
})
}
pub async fn ready(State(state): State<AppState>) -> Json<ReadyResponse> {
Json(ReadyResponse {
status: "ready".to_string(),
sessions: state.session_count().await,
})
}
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn test_health() {
let response = health().await;
assert_eq!(response.status, "ok");
}
}