2025-01-04 05:32:54 +08:00
|
|
|
use axum::{
|
|
|
|
body::Body,
|
|
|
|
http::{Response, StatusCode},
|
2025-03-07 07:21:26 +08:00
|
|
|
middleware as axum_middleware,
|
2025-01-04 05:32:54 +08:00
|
|
|
response::IntoResponse,
|
|
|
|
Json, Router,
|
|
|
|
};
|
|
|
|
|
2025-03-07 07:21:26 +08:00
|
|
|
use middleware::auth;
|
2025-01-04 05:32:54 +08:00
|
|
|
|
|
|
|
mod routes;
|
|
|
|
mod webhooks;
|
|
|
|
|
|
|
|
pub fn router() -> Router {
|
|
|
|
Router::new().nest("/", routes::router()).merge(
|
|
|
|
Router::new()
|
|
|
|
.nest("/webhooks", webhooks::router())
|
2025-03-07 07:21:26 +08:00
|
|
|
.route_layer(axum_middleware::from_fn(auth)),
|
2025-01-04 05:32:54 +08:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum ApiResponse<T> {
|
|
|
|
OK,
|
2025-03-22 02:54:54 +08:00
|
|
|
#[allow(dead_code)]
|
2025-01-07 04:47:32 +08:00
|
|
|
Created,
|
2025-01-04 05:32:54 +08:00
|
|
|
NoContent,
|
|
|
|
JsonData(T),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> IntoResponse for ApiResponse<T>
|
|
|
|
where
|
|
|
|
T: serde::Serialize,
|
|
|
|
{
|
|
|
|
fn into_response(self) -> Response<Body> {
|
|
|
|
match self {
|
|
|
|
Self::OK => (StatusCode::OK).into_response(),
|
|
|
|
Self::Created => (StatusCode::CREATED).into_response(),
|
|
|
|
Self::JsonData(data) => (StatusCode::OK, Json(data)).into_response(),
|
|
|
|
Self::NoContent => (StatusCode::NO_CONTENT).into_response(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|