Add ControllerWsAction
This commit is contained in:
parent
cb47dcda5c
commit
3b596de06f
10 changed files with 134 additions and 34 deletions
emgauwa-lib/src/models
|
@ -1,8 +1,9 @@
|
|||
use crate::db;
|
||||
use crate::db::errors::DatabaseError;
|
||||
use crate::db::{DbRelay, DbSchedule};
|
||||
use crate::types::ControllerUid;
|
||||
use futures::executor;
|
||||
use serde_derive::Serialize;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use sqlx::pool::PoolConnection;
|
||||
use sqlx::Sqlite;
|
||||
|
||||
|
@ -17,22 +18,23 @@ pub trait FromDbModel {
|
|||
Self: Sized;
|
||||
}
|
||||
|
||||
#[derive(Serialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct Schedule {
|
||||
#[serde(flatten)]
|
||||
pub schedule: DbSchedule,
|
||||
pub tags: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct Relay {
|
||||
#[serde(flatten)]
|
||||
pub relay: DbRelay,
|
||||
pub controller: db::DbController,
|
||||
pub controller_id: ControllerUid,
|
||||
pub tags: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct Controller {
|
||||
#[serde(flatten)]
|
||||
pub controller: db::DbController,
|
||||
|
@ -62,11 +64,13 @@ impl FromDbModel for Relay {
|
|||
) -> Result<Self, DatabaseError> {
|
||||
let relay = db_model.clone();
|
||||
let controller = executor::block_on(relay.get_controller(conn))?;
|
||||
let controller_id = controller.uid.clone();
|
||||
let tags = executor::block_on(relay.get_tags(conn))?;
|
||||
|
||||
Ok(Relay {
|
||||
relay,
|
||||
controller,
|
||||
controller_id,
|
||||
tags,
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue