lmrc-cli 0.3.16

CLI tool for scaffolding LMRC Stack infrastructure projects
Documentation
//! Health check HTTP handler (inbound adapter)

use crate::{error::Result, state::AppState};
use axum::{extract::State, response::IntoResponse};
use lmrc_http_common::health::{CheckResult, HealthStatus};

/// Health check endpoint
///
/// GET /health
pub async fn health_check(State(state): State<AppState>) -> Result<impl IntoResponse> {
    // Create health status
    let mut health = HealthStatus::new(env!("CARGO_PKG_VERSION"));

    // Check database connection
    let db_check = match state.db.ping().await {
        Ok(_) => CheckResult::healthy_with_message("Database connected"),
        Err(e) => CheckResult::unhealthy(format!("Database error: {}", e)),
    };

    health = health.with_check("database", db_check);

    Ok(health)
}