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};
|
||||
|
||||
@@ -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(),
|
||||
}),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user