Filled out endpoint to test db

This commit is contained in:
2025-04-01 21:05:36 -04:00
parent e17a304896
commit 401fb94b6b

View File

@@ -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<TestResult>) {
let tr = TestResult {
message: String::from("Should work"),
};
(StatusCode::OK, Json(tr))
pub async fn db_ping(Extension(pool): Extension<sqlx::PgPool>) -> (StatusCode, Json<TestResult>) {
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(),
}),
),
}
}