Filled out endpoint to test db
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
use axum::{Json, http::StatusCode};
|
use axum::{Json, extract::Extension, http::StatusCode};
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
@@ -12,10 +12,19 @@ pub async fn root() -> &'static str {
|
|||||||
"Hello, World!"
|
"Hello, World!"
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn db_ping() -> (StatusCode, Json<TestResult>) {
|
pub async fn db_ping(Extension(pool): Extension<sqlx::PgPool>) -> (StatusCode, Json<TestResult>) {
|
||||||
let tr = TestResult {
|
match sqlx::query("SELECT 1").execute(&pool).await {
|
||||||
message: String::from("Should work"),
|
Ok(_) => {
|
||||||
};
|
let tr = TestResult {
|
||||||
|
message: String::from("This works"),
|
||||||
(StatusCode::OK, Json(tr))
|
};
|
||||||
|
(StatusCode::OK, Json(tr))
|
||||||
|
}
|
||||||
|
Err(e) => (
|
||||||
|
StatusCode::BAD_REQUEST,
|
||||||
|
Json(TestResult {
|
||||||
|
message: e.to_string(),
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user