Code cleanup
All checks were successful
Rust Build / Check (pull_request) Successful in 42s
Rust Build / Test Suite (pull_request) Successful in 53s
Rust Build / Rustfmt (pull_request) Successful in 33s
Rust Build / Clippy (pull_request) Successful in 48s
Rust Build / build (pull_request) Successful in 1m10s
All checks were successful
Rust Build / Check (pull_request) Successful in 42s
Rust Build / Test Suite (pull_request) Successful in 53s
Rust Build / Rustfmt (pull_request) Successful in 33s
Rust Build / Clippy (pull_request) Successful in 48s
Rust Build / build (pull_request) Successful in 1m10s
This commit is contained in:
@@ -1,30 +1,37 @@
|
|||||||
use axum::{Extension, Json, http::StatusCode};
|
pub mod response {
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
#[derive(Deserialize, Serialize)]
|
||||||
|
pub struct TestResult {
|
||||||
#[derive(Deserialize, Serialize)]
|
pub message: String,
|
||||||
pub struct TestResult {
|
}
|
||||||
message: String,
|
}
|
||||||
}
|
|
||||||
|
pub mod endpoint {
|
||||||
// basic handler that responds with a static string
|
use super::*;
|
||||||
pub async fn root() -> &'static str {
|
use axum::{Extension, Json, http::StatusCode};
|
||||||
"Hello, World!"
|
|
||||||
}
|
// basic handler that responds with a static string
|
||||||
|
pub async fn root() -> &'static str {
|
||||||
pub async fn db_ping(Extension(pool): Extension<sqlx::PgPool>) -> (StatusCode, Json<TestResult>) {
|
"Hello, World!"
|
||||||
match sqlx::query("SELECT 1").execute(&pool).await {
|
}
|
||||||
Ok(_) => {
|
|
||||||
let tr = TestResult {
|
pub async fn db_ping(
|
||||||
message: String::from("This works"),
|
Extension(pool): Extension<sqlx::PgPool>,
|
||||||
};
|
) -> (StatusCode, Json<response::TestResult>) {
|
||||||
(StatusCode::OK, Json(tr))
|
match sqlx::query("SELECT 1").execute(&pool).await {
|
||||||
}
|
Ok(_) => {
|
||||||
Err(e) => (
|
let tr = response::TestResult {
|
||||||
StatusCode::BAD_REQUEST,
|
message: String::from("This works"),
|
||||||
Json(TestResult {
|
};
|
||||||
message: e.to_string(),
|
(StatusCode::OK, Json(tr))
|
||||||
}),
|
}
|
||||||
),
|
Err(e) => (
|
||||||
|
StatusCode::BAD_REQUEST,
|
||||||
|
Json(response::TestResult {
|
||||||
|
message: e.to_string(),
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
10
src/main.rs
10
src/main.rs
@@ -25,8 +25,14 @@ mod init {
|
|||||||
pub async fn routes() -> Router {
|
pub async fn routes() -> Router {
|
||||||
// build our application with a route
|
// build our application with a route
|
||||||
Router::new()
|
Router::new()
|
||||||
.route(callers::endpoints::DBTEST, get(callers::common::db_ping))
|
.route(
|
||||||
.route(callers::endpoints::ROOT, get(callers::common::root))
|
callers::endpoints::DBTEST,
|
||||||
|
get(callers::common::endpoint::db_ping),
|
||||||
|
)
|
||||||
|
.route(
|
||||||
|
callers::endpoints::ROOT,
|
||||||
|
get(callers::common::endpoint::root),
|
||||||
|
)
|
||||||
.route(
|
.route(
|
||||||
callers::endpoints::REGISTER,
|
callers::endpoints::REGISTER,
|
||||||
post(callers::register::register_user),
|
post(callers::register::register_user),
|
||||||
|
Reference in New Issue
Block a user