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};
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct TestResult {
|
||||
message: String,
|
||||
pub message: String,
|
||||
}
|
||||
}
|
||||
|
||||
pub mod endpoint {
|
||||
use super::*;
|
||||
use axum::{Extension, Json, http::StatusCode};
|
||||
|
||||
// basic handler that responds with a static string
|
||||
pub async fn root() -> &'static str {
|
||||
"Hello, World!"
|
||||
}
|
||||
|
||||
pub async fn db_ping(Extension(pool): Extension<sqlx::PgPool>) -> (StatusCode, Json<TestResult>) {
|
||||
pub async fn db_ping(
|
||||
Extension(pool): Extension<sqlx::PgPool>,
|
||||
) -> (StatusCode, Json<response::TestResult>) {
|
||||
match sqlx::query("SELECT 1").execute(&pool).await {
|
||||
Ok(_) => {
|
||||
let tr = TestResult {
|
||||
let tr = response::TestResult {
|
||||
message: String::from("This works"),
|
||||
};
|
||||
(StatusCode::OK, Json(tr))
|
||||
}
|
||||
Err(e) => (
|
||||
StatusCode::BAD_REQUEST,
|
||||
Json(TestResult {
|
||||
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 {
|
||||
// build our application with a route
|
||||
Router::new()
|
||||
.route(callers::endpoints::DBTEST, get(callers::common::db_ping))
|
||||
.route(callers::endpoints::ROOT, get(callers::common::root))
|
||||
.route(
|
||||
callers::endpoints::DBTEST,
|
||||
get(callers::common::endpoint::db_ping),
|
||||
)
|
||||
.route(
|
||||
callers::endpoints::ROOT,
|
||||
get(callers::common::endpoint::root),
|
||||
)
|
||||
.route(
|
||||
callers::endpoints::REGISTER,
|
||||
post(callers::register::register_user),
|
||||
|
Reference in New Issue
Block a user