//! API 层 - HTTP 路由和处理器 mod handlers; mod state; pub use state::AppState; use axum::{ routing::{get, post, put, delete}, Router, }; use tower_http::cors::{Any, CorsLayer}; use tower_http::trace::TraceLayer; /// 创建 API 路由 pub fn create_router(state: AppState) -> Router { let cors = CorsLayer::new() .allow_origin(Any) .allow_methods(Any) .allow_headers(Any); Router::new() // 健康检查 .route("/health", get(handlers::health_check)) // 实体账户 API .route("/api/v1/physical-accounts", post(handlers::account::create_physical_account)) .route("/api/v1/physical-accounts", get(handlers::account::list_physical_accounts)) .route("/api/v1/physical-accounts/:id", get(handlers::account::get_physical_account)) .route("/api/v1/physical-accounts/:id/freeze", post(handlers::account::freeze_physical_account)) .route("/api/v1/physical-accounts/:id/unfreeze", post(handlers::account::unfreeze_physical_account)) // 虚拟子账户 API .route("/api/v1/sub-accounts", post(handlers::account::create_sub_account)) .route("/api/v1/sub-accounts/:id", get(handlers::account::get_sub_account)) .route("/api/v1/sub-accounts/:id/balance", get(handlers::account::get_sub_account_balance)) .route("/api/v1/sub-accounts/:id/freeze", post(handlers::account::freeze_sub_account)) .route("/api/v1/sub-accounts/:id/unfreeze", post(handlers::account::unfreeze_sub_account)) .route("/api/v1/sub-accounts/:id/close", post(handlers::account::close_sub_account)) .route("/api/v1/physical-accounts/:id/sub-accounts", get(handlers::account::list_sub_accounts)) // 交易 API .route("/api/v1/transactions/transfer", post(handlers::transaction::transfer)) .route("/api/v1/transactions/deposit", post(handlers::transaction::deposit)) .route("/api/v1/transactions/withdraw", post(handlers::transaction::withdraw)) .route("/api/v1/transactions/:id", get(handlers::transaction::get_transaction)) .route("/api/v1/transactions", get(handlers::transaction::list_transactions)) // 账务 API .route("/api/v1/ledger/subjects", get(handlers::ledger::list_subjects)) .route("/api/v1/ledger/entries/:id", get(handlers::ledger::get_entry)) .route("/api/v1/ledger/accounts/:id/entries", get(handlers::ledger::get_account_entries)) // 对账 API .route("/api/v1/reconciliation/run", post(handlers::reconciliation::run_reconciliation)) .route("/api/v1/reconciliation/batches/:id", get(handlers::reconciliation::get_batch)) .route("/api/v1/reconciliation/batches/:id/items", get(handlers::reconciliation::get_batch_items)) .route("/api/v1/reconciliation/three-account/:account_id", get(handlers::reconciliation::verify_three_account_for_api)) .route("/api/v1/reconciliation/adjustments", post(handlers::reconciliation::create_adjustment)) .route("/api/v1/reconciliation/adjustments/:id/approve", post(handlers::reconciliation::approve_adjustment)) .route("/api/v1/reconciliation/adjustments/:id/reject", post(handlers::reconciliation::reject_adjustment)) .route("/api/v1/reconciliation/adjustments/pending", get(handlers::reconciliation::list_pending_adjustments)) // 积分 API .route("/api/v1/points/accounts/:sub_account_id", get(handlers::points::get_points_accounts)) .route("/api/v1/points/earn", post(handlers::points::earn_points)) .route("/api/v1/points/spend", post(handlers::points::spend_points)) .route("/api/v1/points/transfer", post(handlers::points::transfer_points)) .route("/api/v1/points/transactions", get(handlers::points::list_transactions)) .layer(TraceLayer::new_for_http()) .layer(cors) .with_state(state) }