Files
vmall/apps/api/src/modules/health.rs
T
Chengdong ZhangandCursor 5e866d08f4 refactor(api): split Axum handlers into handler/service/repo modules
Keep the REST contract; move domain logic out of route files so checkout, fulfillment, and identity can be reused across customer, shop, and admin surfaces.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-18 14:59:36 +08:00

28 lines
742 B
Rust

use axum::{extract::State, routing::get, Json, Router};
use redis::AsyncCommands;
use serde_json::{json, Value};
use crate::error::ApiResult;
use crate::state::AppState;
pub fn router() -> Router<AppState> {
Router::new().route("/ready", get(ready))
}
pub async fn health() -> Json<Value> {
Json(json!({ "status": "ok" }))
}
pub async fn ready(State(state): State<AppState>) -> ApiResult<Json<Value>> {
let db_ok = sqlx::query_scalar::<_, i32>("SELECT 1")
.fetch_one(&state.db)
.await
.is_ok();
let mut redis = state.redis.clone();
let redis_ok = redis
.set::<_, _, ()>("vmall:ready:ping", "1")
.await
.is_ok();
Ok(Json(json!({ "db": db_ok, "redis": redis_ok })))
}