Added a bunch of things

This commit is contained in:
didier amyot committed 2023-03-10 16:34:56 -05:00
1 parent c365289914
commit ce92916942
15 files changed
+131 -55

No files matched your search

+12 -5
View File
@@ -1,4 +1,4 @@
use crate::services::{SessionService, UserService};
use crate::services::{SecurityService, SessionService, UserService};
use actix_web::{error, Result};
use r2d2::PooledConnection;
@@ -19,17 +19,17 @@ struct ServicesCache {
}
#[derive(Clone)]
pub struct Services {
pub struct ServicesFactory {
pool: DbPool,
cache: ServicesCache,
}
impl Services {
pub fn new(pool: DbPool) -> Services {
impl ServicesFactory {
pub fn new(pool: DbPool) -> ServicesFactory {
let mut conn = pool.get().unwrap();
let session_service = SessionService::from_conn(&mut conn).unwrap();
let cache = ServicesCache { session_service };
Services { pool, cache }
ServicesFactory { pool, cache }
}
pub fn get_connection(&self) -> Result<PooledConnection<SqliteConnectionManager>> {
@@ -48,4 +48,11 @@ impl Services {
) -> Result<UserService> {
Ok(UserService::new(conn))
}
pub fn get_security_service<'a>(
&'a self,
conn: &'a PooledConnection<SqliteConnectionManager>,
) -> Result<SecurityService> {
Ok(SecurityService::new(conn))
}
}