summaryrefslogtreecommitdiffstats
path: root/crates/profile-service/src/state.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/profile-service/src/state.rs')
-rw-r--r--crates/profile-service/src/state.rs42
1 files changed, 42 insertions, 0 deletions
diff --git a/crates/profile-service/src/state.rs b/crates/profile-service/src/state.rs
new file mode 100644
index 0000000..1ccfbfd
--- /dev/null
+++ b/crates/profile-service/src/state.rs
@@ -0,0 +1,42 @@
+use std::sync::Arc;
+
+use sqlx::PgPool;
+use stack_up::{Configuration, cache::RedisManager};
+
+use crate::cnfg::LocalConfig;
+
+#[derive(Clone)]
+pub struct AppHandle(Arc<AppState>);
+
+impl std::ops::Deref for AppHandle {
+ type Target = Arc<AppState>;
+
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+}
+
+#[derive(Clone)]
+pub struct Services {
+ pub postgres: PgPool,
+ pub cache: RedisManager,
+}
+
+pub struct AppState {
+ pub services: Services,
+ pub local_config: LocalConfig,
+}
+
+impl AppState {
+ pub async fn create(
+ services: Services,
+ configuration: &Configuration,
+ ) -> Result<AppHandle, anyhow::Error> {
+ let local_config: LocalConfig = serde_json::from_value(configuration.misc.clone())?;
+
+ Ok(AppHandle(Arc::new(Self {
+ services,
+ local_config,
+ })))
+ }
+}