Apply small fixes and prepare emgauwa-controller

This commit is contained in:
Tobias Reisinger 2023-11-22 23:28:03 +01:00
parent bacea1e3e9
commit d5583e86bc
9 changed files with 88 additions and 4 deletions

BIN
Cargo.lock generated

Binary file not shown.

View file

@ -2,5 +2,6 @@
resolver = "2" resolver = "2"
members = [ members = [
"emgauwa-core", "emgauwa-core",
"emgauwa-controller",
"emgauwa-lib", "emgauwa-lib",
] ]

View file

@ -0,0 +1,24 @@
[package]
name = "emgauwa-controller"
version = "0.5.0"
edition = "2021"
authors = ["Tobias Reisinger <tobias@msrg.cc>"]
[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"

View file

@ -0,0 +1,5 @@
mod settings;
fn main() {
let _settings = settings::init();
}

View file

@ -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::<Settings>()
.unwrap_or_else(|_| panic!("Error reading settings."))
}

View file

@ -1,6 +1,6 @@
[package] [package]
name = "emgauwa-core" name = "emgauwa-core"
version = "0.1.0" version = "0.5.0"
edition = "2021" edition = "2021"
authors = ["Tobias Reisinger <tobias@msrg.cc>"] authors = ["Tobias Reisinger <tobias@msrg.cc>"]

View file

@ -43,7 +43,7 @@ pub fn init() -> Settings {
Config::builder() Config::builder()
.add_source(config::File::with_name("emgauwa-core")) .add_source(config::File::with_name("emgauwa-core"))
.add_source( .add_source(
config::Environment::with_prefix("EMGAUWA") config::Environment::with_prefix("EMGAUWA_CORE")
.prefix_separator("_") .prefix_separator("_")
.separator("__"), .separator("__"),
) )

View file

@ -1,9 +1,10 @@
[package] [package]
name = "emgauwa-lib" name = "emgauwa-lib"
version = "0.1.0" version = "0.5.0"
edition = "2021" edition = "2021"
authors = ["Tobias Reisinger <tobias@msrg.cc>"] authors = ["Tobias Reisinger <tobias@msrg.cc>"]
[dependencies] [dependencies]
actix = "0.13" actix = "0.13"
actix-web = "4.4" actix-web = "4.4"

View file

@ -21,7 +21,6 @@ async fn get_schedules(pool: &mut Pool<Sqlite>) -> Result<Vec<Schedule>, ApiErro
Ok(Schedule::get_all(&mut pool_conn).await?) Ok(Schedule::get_all(&mut pool_conn).await?)
} }
/// Handler for ws::Message message
impl StreamHandler<Result<Message, ProtocolError>> for ControllerWs { impl StreamHandler<Result<Message, ProtocolError>> for ControllerWs {
fn handle(&mut self, msg: Result<Message, ProtocolError>, ctx: &mut Self::Context) { fn handle(&mut self, msg: Result<Message, ProtocolError>, ctx: &mut Self::Context) {
let schedules = futures::executor::block_on(get_schedules(&mut self.pool)).unwrap(); let schedules = futures::executor::block_on(get_schedules(&mut self.pool)).unwrap();