This commit is contained in:
2025-10-09 22:16:29 +02:00
commit 768f8cb21c
33 changed files with 12047 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
use std::sync::Arc;
use aws_sdk_s3::Client as S3Client;
use diesel::{
pg::PgConnection,
r2d2::{ConnectionManager, PooledConnection},
};
use crate::{
auth::jwt::JwtService,
config::AppConfig,
db::PgPool,
error::{AppError, AppResult},
};
type PgPooledConnection = PooledConnection<ConnectionManager<PgConnection>>;
#[derive(Clone)]
pub struct AppState {
pub pool: PgPool,
pub config: Arc<AppConfig>,
pub s3: S3Client,
pub jwt: JwtService,
}
impl AppState {
pub fn new(pool: PgPool, config: AppConfig, s3: S3Client, jwt: JwtService) -> Self {
Self {
pool,
config: Arc::new(config),
s3,
jwt,
}
}
pub fn db(&self) -> AppResult<PgPooledConnection> {
self.pool
.get()
.map_err(|err| AppError::internal(format!("database pool error: {err}")))
}
}