diff --git a/Cargo.lock b/Cargo.lock index 84a38da..45f0255 100644 Binary files a/Cargo.lock and b/Cargo.lock differ 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();