feat: with persistent session state

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2023-05-28 15:34:36 +02:00
parent 1e38b2838c
commit 746fb68684
9 changed files with 661 additions and 232 deletions

View File

@@ -6,32 +6,20 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
como_core = { path = "../como_core" }
como_domain = { path = "../como_domain" }
como_core.workspace = true
como_domain.workspace = true
async-graphql = "4.0.6"
async-graphql-axum = "*"
axum = "0.5.13"
axum-extra = { version = "*", features = ["cookie", "cookie-private"] }
axum-sessions = { version = "*" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.68"
tokio = { version = "1.20.1", features = ["full"] }
uuid = { version = "1.1.2", features = ["v4", "fast-rng"] }
sqlx = { version = "0.6", features = [
"runtime-tokio-rustls",
"postgres",
"migrate",
"uuid",
"offline",
] }
anyhow = "1.0.60"
dotenv = "0.15.0"
tracing = "0.1.36"
tracing-subscriber = { version = "0.3.15", features = ["env-filter"] }
tower-http = { version = "0.3.4", features = ["full"] }
argon2 = "0.4"
rand_core = { version = "0.6", features = ["std"] }
cookie = { version = "0.16", features = ["secure", "percent-encode"] }
axum.workspace = true
async-trait.workspace = true
uuid.workspace = true
anyhow.workspace = true
sqlx.workspace = true
async-sqlx-session.workspace = true
tokio.workspace = true
clap.workspace = true
tracing.workspace = true
argon2.workspace = true
rand_core.workspace = true

View File

@@ -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,
})
}
}

View File

@@ -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},