Add ControllerWsAction

This commit is contained in:
Tobias Reisinger 2023-11-27 17:21:40 +01:00
parent cb47dcda5c
commit 3b596de06f
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
10 changed files with 134 additions and 34 deletions
emgauwa-lib/src/db

View file

@ -1,4 +1,4 @@
use serde_derive::Serialize;
use serde_derive::{Deserialize, Serialize};
use std::ops::DerefMut;
use crate::db::DbController;
@ -8,7 +8,7 @@ use sqlx::Sqlite;
use crate::db::errors::DatabaseError;
use crate::db::DbTag;
#[derive(Debug, Serialize, Clone, sqlx::FromRow)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DbRelay {
#[serde(skip)]
pub id: i64,
@ -51,6 +51,18 @@ impl DbRelay {
.await?)
}
pub async fn get_by_controller_and_num_or_create(
conn: &mut PoolConnection<Sqlite>,
controller: &DbController,
number: i64,
new_name: &str,
) -> Result<DbRelay, DatabaseError> {
match DbRelay::get_by_controller_and_num(conn, controller, number).await? {
Some(relay) => Ok(relay),
None => DbRelay::create(conn, new_name, number, controller).await,
}
}
pub async fn get_by_tag(
conn: &mut PoolConnection<Sqlite>,
tag: &DbTag,