use std::sync::Arc; use diesel::{ pg::PgConnection, r2d2::{ConnectionManager, PooledConnection}, }; use crate::{ auth::jwt::JwtService, config::AppConfig, db::PgPool, error::{AppError, AppResult}, storage::ObjectStorage, }; type PgPooledConnection = PooledConnection>; #[derive(Clone)] pub struct AppState { pub pool: PgPool, pub config: Arc, pub storage: Arc, pub jwt: JwtService, } impl AppState { pub fn new( pool: PgPool, config: AppConfig, storage: Arc, jwt: JwtService, ) -> Self { Self { pool, config: Arc::new(config), storage, jwt, } } pub fn db(&self) -> AppResult { self.pool .get() .map_err(|err| AppError::internal(format!("database pool error: {err}"))) } }