Add self-creation for controller
This commit is contained in:
parent
d193000aec
commit
4e3df272c3
10 changed files with 105 additions and 14 deletions
emgauwa-lib/src
|
@ -8,16 +8,16 @@ use crate::db::errors::DatabaseError;
|
|||
use crate::db::model_utils::Period;
|
||||
use crate::db::types::ScheduleUid;
|
||||
|
||||
// export for easier/flatter access
|
||||
pub use crate::db::schedules::{Periods, Schedule};
|
||||
|
||||
pub mod errors;
|
||||
mod model_utils;
|
||||
mod models;
|
||||
pub mod schedules;
|
||||
mod schedules;
|
||||
pub mod tag;
|
||||
pub mod types;
|
||||
pub mod controllers;
|
||||
mod controllers;
|
||||
|
||||
pub use controllers::Controller;
|
||||
pub use schedules::{Periods, Schedule};
|
||||
|
||||
static MIGRATOR: Migrator = sqlx::migrate!("../migrations"); // defaults to "./migrations"
|
||||
|
||||
|
|
|
@ -9,6 +9,12 @@ use uuid::Uuid;
|
|||
#[derive(Clone, Debug)]
|
||||
pub struct ControllerUid(Uuid);
|
||||
|
||||
impl ControllerUid {
|
||||
pub fn new() -> Self {
|
||||
Self(Uuid::new_v4())
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for ControllerUid {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
|
|
|
@ -25,10 +25,12 @@ impl StreamHandler<Result<Message, ProtocolError>> for ControllerWs {
|
|||
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_json = serde_json::to_string(&schedules).unwrap();
|
||||
println!("{:?}", msg);
|
||||
match msg {
|
||||
Ok(Message::Ping(msg)) => ctx.pong(&msg),
|
||||
Ok(Message::Text(_text)) => ctx.text(schedules_json),
|
||||
Ok(Message::Text(text)) => {
|
||||
println!("Got text: {}", text.to_string());
|
||||
ctx.text(schedules_json)
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::db::schedules::Schedule;
|
||||
use crate::db::Schedule;
|
||||
use futures::executor;
|
||||
use serde::Serialize;
|
||||
use sqlx::pool::PoolConnection;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue