feat: role routing

This commit is contained in:
Ahmet Kaan GÜMÜŞ 2024-12-13 21:55:04 +03:00
parent 00d6bd5b93
commit d0187b1b42
7 changed files with 172 additions and 6 deletions

24
src/routing.rs Normal file
View file

@ -0,0 +1,24 @@
pub mod role;
use axum::{extract::State, http::StatusCode, response::IntoResponse, routing::get, Router};
use tower_http::cors::CorsLayer;
use crate::{database, AppState};
pub async fn route(State(app_state): State<AppState>) -> Router {
Router::new()
.route("/", get(alive))
.nest(
"/role",
role::route(axum::extract::State(app_state.clone())),
)
.layer(CorsLayer::permissive())
.with_state(app_state)
}
async fn alive(State(app_state): State<AppState>) -> impl IntoResponse {
match database::is_alive(&app_state.database_connection).await {
true => StatusCode::OK,
false => StatusCode::SERVICE_UNAVAILABLE,
}
}