feat: with persistent session state
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use async_sqlx_session::PostgresSessionStore;
|
||||
use como_core::{items::DynItemService, projects::DynProjectService, users::DynUserService};
|
||||
use tracing::log::info;
|
||||
|
||||
@@ -17,22 +18,25 @@ pub struct ServiceRegister {
|
||||
pub item_service: DynItemService,
|
||||
pub project_service: DynProjectService,
|
||||
pub user_service: DynUserService,
|
||||
pub session_store: PostgresSessionStore,
|
||||
}
|
||||
|
||||
impl ServiceRegister {
|
||||
pub fn new(pool: ConnectionPool, _config: Arc<AppConfig>) -> Self {
|
||||
pub async fn new(pool: ConnectionPool, config: Arc<AppConfig>) -> anyhow::Result<Self> {
|
||||
info!("creating services");
|
||||
|
||||
let item_service = Arc::new(MemoryItemService::new()) as DynItemService;
|
||||
let project_service = Arc::new(MemoryProjectService::new()) as DynProjectService;
|
||||
let user_service = Arc::new(DefaultUserService::new(pool.clone())) as DynUserService;
|
||||
let store = PostgresSessionStore::new(&config.database_url).await?;
|
||||
|
||||
info!("services created succesfully");
|
||||
|
||||
return Self {
|
||||
Ok(Self {
|
||||
item_service,
|
||||
user_service,
|
||||
project_service,
|
||||
};
|
||||
session_store: store,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@ use std::{
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
use axum::async_trait;
|
||||
use async_trait::async_trait;
|
||||
use como_core::items::ItemService;
|
||||
use como_domain::item::{
|
||||
queries::{GetItemQuery, GetItemsQuery},
|
||||
|
Reference in New Issue
Block a user