backend/controller/
health.rs

1//! Health endpoint.
2
3use actix_http::StatusCode;
4use actix_web::{get, HttpResponse, Result};
5
6use crate::config::data::SharedPool;
7use crate::error::ServiceError;
8use crate::service::health;
9
10/// Endpoint for getting the health status of the backend.
11///
12/// # Errors
13/// * If the connection to the database could not be established.
14#[utoipa::path(
15    context_path = "/api/health",
16    responses(
17        (status = 200, description = "Backend is healthy"),
18        (status = 503, description = "One or more services are unavailable")
19    )
20)]
21#[get("")]
22pub async fn get(pool: SharedPool) -> Result<HttpResponse> {
23    health::get(&pool)
24        .await
25        .map_err(|e| ServiceError::new(StatusCode::SERVICE_UNAVAILABLE, &e.reason))?;
26    Ok(HttpResponse::Ok().body("OK"))
27}