fix: do some fix

This commit is contained in:
2025-03-09 01:22:30 +08:00
parent f94e175082
commit 07ac7e3376
29 changed files with 422 additions and 628 deletions

View File

@@ -0,0 +1,40 @@
use std::sync::Arc;
use axum::{Json, Router, extract::State, routing::get};
use serde::Serialize;
use crate::{app::AppContextTrait, errors::RResult, web::controller::Controller};
pub const CONTROLLER_PREFIX: &str = "/api/metadata";
#[derive(Serialize)]
pub struct StandardResponse {
pub success: bool,
pub message: String,
}
async fn health(State(ctx): State<Arc<dyn AppContextTrait>>) -> RResult<Json<StandardResponse>> {
ctx.db().ping().await.inspect_err(
|err| tracing::error!(err.msg = %err, err.detail = ?err, "health check database ping error"),
)?;
Ok(Json(StandardResponse {
success: true,
message: "ok".to_string(),
}))
}
async fn ping() -> Json<StandardResponse> {
Json(StandardResponse {
success: true,
message: "ok".to_string(),
})
}
pub async fn create(_context: Arc<dyn AppContextTrait>) -> RResult<Controller> {
let router = Router::<Arc<dyn AppContextTrait>>::new()
.route("/health", get(health))
.route("/ping", get(ping));
Ok(Controller::from_prefix(CONTROLLER_PREFIX, router))
}

View File

@@ -1,5 +1,6 @@
pub mod core;
pub mod graphql;
pub mod metadata;
pub mod oidc;
pub use core::{Controller, ControllerTrait, PrefixController};