avl_console/
api.rs

1//! REST API routes
2
3use crate::state::AppState;
4use axum::{
5    routing::get,
6    Json, Router,
7};
8use serde::Serialize;
9use std::sync::Arc;
10
11pub fn routes(state: Arc<AppState>) -> Router {
12    Router::new()
13        .route("/health", get(health_check))
14        .route("/version", get(version))
15        .nest("/auth", crate::auth::routes(state.clone()))
16}
17
18#[derive(Serialize)]
19struct HealthResponse {
20    status: String,
21    version: String,
22    services: ServiceStatus,
23}
24
25#[derive(Serialize)]
26struct ServiceStatus {
27    aviladb: bool,
28    storage: bool,
29    observability: bool,
30}
31
32async fn health_check() -> Json<HealthResponse> {
33    Json(HealthResponse {
34        status: "healthy".to_string(),
35        version: env!("CARGO_PKG_VERSION").to_string(),
36        services: ServiceStatus {
37            aviladb: true,
38            storage: true,
39            observability: true,
40        },
41    })
42}
43
44#[derive(Serialize)]
45struct VersionResponse {
46    version: String,
47    build_date: String,
48    git_commit: String,
49}
50
51async fn version() -> Json<VersionResponse> {
52    Json(VersionResponse {
53        version: env!("CARGO_PKG_VERSION").to_string(),
54        build_date: "2024-11-23".to_string(),
55        git_commit: "dev".to_string(),
56    })
57}