From d5583e86bc92de0f61634dd513fd33df7e19121b Mon Sep 17 00:00:00 2001 From: Tobias Reisinger Date: Wed, 22 Nov 2023 23:28:03 +0100 Subject: [PATCH] Apply small fixes and prepare emgauwa-controller --- Cargo.lock | Bin 72666 -> 73888 bytes Cargo.toml | 1 + emgauwa-controller/Cargo.toml | 24 ++++++++ emgauwa-controller/src/main.rs | 5 ++ emgauwa-controller/src/settings.rs | 54 ++++++++++++++++++ emgauwa-core/Cargo.toml | 2 +- emgauwa-core/src/settings.rs | 2 +- emgauwa-lib/Cargo.toml | 3 +- emgauwa-lib/src/handlers/v1/ws/controllers.rs | 1 - 9 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 emgauwa-controller/Cargo.toml create mode 100644 emgauwa-controller/src/main.rs create mode 100644 emgauwa-controller/src/settings.rs diff --git a/Cargo.lock b/Cargo.lock index 84a38da86e8997d9e449168768b34cfda2f7b137..45f02555a816584b22a6e3868f5069ff181e2e55 100644 GIT binary patch delta 644 zcmZuvziU)M5GLVFBpUSej2x$MIYb1#usi$S?!Ln0Ql(153EGM5?#$jD9`A*BFYyoX z53txuZ1gWMc!jlCS}E9A7{$)U%2s?nf5jkE%=f_z^L;b(?s@I;i`xFJjgzJ@T}oYs zqjV4k?@dopBEj&)QtZ4FURW;?wU?Z1%s5kC#L}Py#k{qGFyfJtvEpczE}O#o>iOx- zjh(q>TIAVyOnGNvkMhYVOWW7m9kvp$gx9^L(AwIo7unrW)-86^!K9#cR8UB_FNOWB z`S5b{?Ch_?gHxx&x6N1o(ks*E_ROOThgy$J0T$Np_t$^}#^`M6$PtsMdFj9jWZoOW zfqP0+WR>ttYNtViv)l;~P!a#A_TW8_XpU?axBDJiA5NmxE{E_|4; z1^uRR8xP;C(lacIoj<_j6ROBK8&o+rDOO-IG`s@Ea5SMj&+>}x=Hs8a@Le71pIX!9 zFAwG#KiCm7D)b)qS6SkmCQ^W4$~SQy${m4ls diff --git a/Cargo.toml b/Cargo.toml index f8e9722..6da926b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,5 +2,6 @@ resolver = "2" members = [ "emgauwa-core", + "emgauwa-controller", "emgauwa-lib", ] diff --git a/emgauwa-controller/Cargo.toml b/emgauwa-controller/Cargo.toml new file mode 100644 index 0000000..5a3cc45 --- /dev/null +++ b/emgauwa-controller/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "emgauwa-controller" +version = "0.5.0" +edition = "2021" +authors = ["Tobias Reisinger "] + +[dependencies] +emgauwa-lib = { path = "../emgauwa-lib" } + +config = "0.13" + +tokio-tungstenite = "0.20" + +simple_logger = "4.2" +log = "0.4" + +chrono = { version = "0.4", features = ["serde"] } +uuid = { version = "1.5", features = ["serde", "v4"] } + +serde = "1.0" +serde_json = "1.0" +serde_derive = "1.0" + +futures = "0.3.29" diff --git a/emgauwa-controller/src/main.rs b/emgauwa-controller/src/main.rs new file mode 100644 index 0000000..031a0d1 --- /dev/null +++ b/emgauwa-controller/src/main.rs @@ -0,0 +1,5 @@ +mod settings; + +fn main() { + let _settings = settings::init(); +} diff --git a/emgauwa-controller/src/settings.rs b/emgauwa-controller/src/settings.rs new file mode 100644 index 0000000..a2b6ead --- /dev/null +++ b/emgauwa-controller/src/settings.rs @@ -0,0 +1,54 @@ +use config::Config; +use serde_derive::Deserialize; + +#[derive(Clone, Debug, Deserialize)] +#[serde(default)] +#[allow(unused)] +pub struct Logging { + pub level: String, + pub file: String, +} + +#[derive(Clone, Debug, Deserialize)] +#[serde(default)] +#[allow(unused)] +pub struct Settings { + pub database: String, + pub port: u16, + pub host: String, + pub logging: Logging, +} + +impl Default for Settings { + fn default() -> Self { + Settings { + database: String::from("sqlite://emgauwa-controller.sqlite"), + port: 5000, + host: String::from("127.0.0.1"), + logging: Logging::default(), + } + } +} + +impl Default for Logging { + fn default() -> Self { + Logging { + level: String::from("info"), + file: String::from("stdout"), + } + } +} + +pub fn init() -> Settings { + Config::builder() + .add_source(config::File::with_name("emgauwa-controller")) + .add_source( + config::Environment::with_prefix("EMGAUWA_CONTROLLER") + .prefix_separator("_") + .separator("__"), + ) + .build() + .unwrap() + .try_deserialize::() + .unwrap_or_else(|_| panic!("Error reading settings.")) +} diff --git a/emgauwa-core/Cargo.toml b/emgauwa-core/Cargo.toml index 47c0eaa..b033de4 100644 --- a/emgauwa-core/Cargo.toml +++ b/emgauwa-core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "emgauwa-core" -version = "0.1.0" +version = "0.5.0" edition = "2021" authors = ["Tobias Reisinger "] diff --git a/emgauwa-core/src/settings.rs b/emgauwa-core/src/settings.rs index cff1e7a..44b29db 100644 --- a/emgauwa-core/src/settings.rs +++ b/emgauwa-core/src/settings.rs @@ -43,7 +43,7 @@ pub fn init() -> Settings { Config::builder() .add_source(config::File::with_name("emgauwa-core")) .add_source( - config::Environment::with_prefix("EMGAUWA") + config::Environment::with_prefix("EMGAUWA_CORE") .prefix_separator("_") .separator("__"), ) diff --git a/emgauwa-lib/Cargo.toml b/emgauwa-lib/Cargo.toml index eecb0fb..96aa5c5 100644 --- a/emgauwa-lib/Cargo.toml +++ b/emgauwa-lib/Cargo.toml @@ -1,9 +1,10 @@ [package] name = "emgauwa-lib" -version = "0.1.0" +version = "0.5.0" edition = "2021" authors = ["Tobias Reisinger "] + [dependencies] actix = "0.13" actix-web = "4.4" diff --git a/emgauwa-lib/src/handlers/v1/ws/controllers.rs b/emgauwa-lib/src/handlers/v1/ws/controllers.rs index d357195..9766045 100644 --- a/emgauwa-lib/src/handlers/v1/ws/controllers.rs +++ b/emgauwa-lib/src/handlers/v1/ws/controllers.rs @@ -21,7 +21,6 @@ async fn get_schedules(pool: &mut Pool) -> Result, ApiErro Ok(Schedule::get_all(&mut pool_conn).await?) } -/// Handler for ws::Message message impl StreamHandler> for ControllerWs { fn handle(&mut self, msg: Result, ctx: &mut Self::Context) { let schedules = futures::executor::block_on(get_schedules(&mut self.pool)).unwrap();