diff --git a/src/callers/common.rs b/src/callers/common.rs index bdf5e0b..0e29287 100644 --- a/src/callers/common.rs +++ b/src/callers/common.rs @@ -1,4 +1,4 @@ -use axum::{Json, http::StatusCode}; +use axum::{Json, extract::Extension, http::StatusCode}; use serde::{Deserialize, Serialize}; @@ -12,10 +12,19 @@ pub async fn root() -> &'static str { "Hello, World!" } -pub async fn db_ping() -> (StatusCode, Json) { - let tr = TestResult { - message: String::from("Should work"), - }; - - (StatusCode::OK, Json(tr)) +pub async fn db_ping(Extension(pool): Extension) -> (StatusCode, Json) { + match sqlx::query("SELECT 1").execute(&pool).await { + Ok(_) => { + let tr = TestResult { + message: String::from("This works"), + }; + (StatusCode::OK, Json(tr)) + } + Err(e) => ( + StatusCode::BAD_REQUEST, + Json(TestResult { + message: e.to_string(), + }), + ), + } }