Keep the REST contract; move domain logic out of route files so checkout, fulfillment, and identity can be reused across customer, shop, and admin surfaces. Co-authored-by: Cursor <cursoragent@cursor.com>
21 lines
698 B
Rust
21 lines
698 B
Rust
use sqlx::PgPool;
|
|
|
|
#[derive(Clone)]
|
|
pub struct AppState {
|
|
pub db: PgPool,
|
|
pub redis: redis::aio::ConnectionManager,
|
|
pub config: crate::config::Config,
|
|
}
|
|
|
|
pub async fn build_state(config: &crate::config::Config) -> anyhow::Result<AppState> {
|
|
let db = PgPool::connect(&config.database_url).await?;
|
|
assemble(config.clone(), db).await
|
|
}
|
|
|
|
/// Build state from an already-open pool (migrate + serve share one pool).
|
|
pub async fn assemble(config: crate::config::Config, db: PgPool) -> anyhow::Result<AppState> {
|
|
let client = redis::Client::open(config.redis_url.clone())?;
|
|
let redis = redis::aio::ConnectionManager::new(client).await?;
|
|
Ok(AppState { db, redis, config })
|
|
}
|