2024-12-15 20:56:24 +03:00
|
|
|
pub mod comment;
|
2024-12-16 01:26:22 +03:00
|
|
|
pub mod comment_interaction;
|
2024-12-17 02:29:41 +03:00
|
|
|
pub mod contact;
|
2024-12-15 21:07:58 +03:00
|
|
|
pub mod interaction;
|
2025-01-11 17:29:18 +03:00
|
|
|
pub mod login;
|
2025-01-19 23:47:09 +03:00
|
|
|
pub mod middleware;
|
2024-12-15 04:30:39 +03:00
|
|
|
pub mod post;
|
2024-12-16 01:20:10 +03:00
|
|
|
pub mod post_interaction;
|
2024-12-13 21:55:04 +03:00
|
|
|
pub mod role;
|
2024-12-14 03:11:39 +03:00
|
|
|
pub mod user;
|
2024-12-17 02:40:02 +03:00
|
|
|
pub mod user_contact;
|
2024-12-13 21:55:04 +03:00
|
|
|
|
|
|
|
use axum::{extract::State, http::StatusCode, response::IntoResponse, routing::get, Router};
|
2025-01-10 23:11:00 +03:00
|
|
|
use tower::limit::ConcurrencyLimitLayer;
|
2024-12-13 21:55:04 +03:00
|
|
|
use tower_http::cors::CorsLayer;
|
|
|
|
|
|
|
|
use crate::{database, AppState};
|
|
|
|
|
2025-01-11 17:29:18 +03:00
|
|
|
pub async fn route(concurrency_limit: &usize, State(app_state): State<AppState>) -> Router {
|
2024-12-13 21:55:04 +03:00
|
|
|
Router::new()
|
|
|
|
.route("/", get(alive))
|
2025-01-19 23:47:09 +03:00
|
|
|
.route_layer(axum::middleware::from_fn_with_state(
|
|
|
|
app_state.clone(),
|
|
|
|
middleware::pass,
|
|
|
|
))
|
2024-12-13 21:55:04 +03:00
|
|
|
.nest(
|
2024-12-15 20:56:24 +03:00
|
|
|
"/roles",
|
2024-12-13 21:55:04 +03:00
|
|
|
role::route(axum::extract::State(app_state.clone())),
|
|
|
|
)
|
2024-12-14 03:11:39 +03:00
|
|
|
.nest(
|
2024-12-15 20:56:24 +03:00
|
|
|
"/users",
|
2024-12-14 03:11:39 +03:00
|
|
|
user::route(axum::extract::State(app_state.clone())),
|
|
|
|
)
|
2024-12-15 20:56:24 +03:00
|
|
|
.nest(
|
|
|
|
"/posts",
|
|
|
|
post::route(axum::extract::State(app_state.clone())),
|
|
|
|
)
|
|
|
|
.nest(
|
|
|
|
"/comments",
|
|
|
|
comment::route(axum::extract::State(app_state.clone())),
|
|
|
|
)
|
2024-12-15 21:07:58 +03:00
|
|
|
.nest(
|
|
|
|
"/interactions",
|
|
|
|
interaction::route(axum::extract::State(app_state.clone())),
|
|
|
|
)
|
2024-12-16 01:20:10 +03:00
|
|
|
.nest(
|
|
|
|
"/post_interactions",
|
|
|
|
post_interaction::route(axum::extract::State(app_state.clone())),
|
|
|
|
)
|
2024-12-16 01:26:22 +03:00
|
|
|
.nest(
|
|
|
|
"/comment_interactions",
|
|
|
|
comment_interaction::route(axum::extract::State(app_state.clone())),
|
|
|
|
)
|
2024-12-17 02:29:41 +03:00
|
|
|
.nest(
|
|
|
|
"/contacts",
|
|
|
|
contact::route(axum::extract::State(app_state.clone())),
|
|
|
|
)
|
2024-12-17 02:40:02 +03:00
|
|
|
.nest(
|
|
|
|
"/user_contacts",
|
|
|
|
user_contact::route(axum::extract::State(app_state.clone())),
|
|
|
|
)
|
2024-12-13 21:55:04 +03:00
|
|
|
.layer(CorsLayer::permissive())
|
2025-01-11 17:29:18 +03:00
|
|
|
.layer(ConcurrencyLimitLayer::new(*concurrency_limit))
|
2024-12-13 21:55:04 +03:00
|
|
|
.with_state(app_state)
|
|
|
|
}
|
|
|
|
|
2025-01-19 23:47:09 +03:00
|
|
|
pub async fn alive(State(app_state): State<AppState>) -> impl IntoResponse {
|
2024-12-13 21:55:04 +03:00
|
|
|
match database::is_alive(&app_state.database_connection).await {
|
|
|
|
true => StatusCode::OK,
|
|
|
|
false => StatusCode::SERVICE_UNAVAILABLE,
|
|
|
|
}
|
|
|
|
}
|