From bb622df89b7d662c9df3dc3805c4dfa53549732b Mon Sep 17 00:00:00 2001 From: GW_MC <72297530+GWMCwing@users.noreply.github.com> Date: Thu, 27 Nov 2025 18:50:11 +0800 Subject: [PATCH] Basic route structure --- apps/api/src/main.rs | 7 ++++++- apps/api/src/routes.rs | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 apps/api/src/routes.rs diff --git a/apps/api/src/main.rs b/apps/api/src/main.rs index b563267..9529a15 100644 --- a/apps/api/src/main.rs +++ b/apps/api/src/main.rs @@ -1,4 +1,5 @@ mod config; +mod routes; mod tasks; use axum::Router; @@ -59,7 +60,11 @@ async fn main() { // build the axum app and run the server... info!("Starting application..."); - let app: Router = Router::new(); + let app: Router = routes::get_root_router(routes::AppState { + database_connection: db_connection, + service: std::sync::Arc::new(routes::AppService {}), + }); + let address = format!("{}:{}", settings.server.address, settings.server.port); info!("Starting server at http://{}", address); diff --git a/apps/api/src/routes.rs b/apps/api/src/routes.rs new file mode 100644 index 0000000..a3a3a32 --- /dev/null +++ b/apps/api/src/routes.rs @@ -0,0 +1,33 @@ +use std::sync::Arc; + +use axum::Router; +use migration::sea_orm::DatabaseConnection; + +pub struct AppState { + pub database_connection: DatabaseConnection, + pub service: Arc, +} + +pub struct AppService { + // +} + +pub fn get_root_router(state: impl Into>) -> Router { + let router = Router::new() + // TODO: Add routes + .with_state(state.into()); + + #[allow(clippy::let_and_return)] + router +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn ensure_state_send_sync() { + fn assert_send_sync() {} + assert_send_sync::(); + } +}