Add app_state reload util and add handler for weekday change
This commit is contained in:
parent
97d9222a39
commit
6414083af0
5 changed files with 51 additions and 38 deletions
emgauwa-lib/src/db
|
@ -1,11 +1,14 @@
|
|||
use std::ops::DerefMut;
|
||||
|
||||
use futures::executor::block_on;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use sqlx::pool::PoolConnection;
|
||||
use sqlx::Sqlite;
|
||||
|
||||
use crate::db::{DbController, DbJunctionTag, DbTag};
|
||||
use crate::db::{DbController, DbJunctionRelaySchedule, DbJunctionTag, DbSchedule, DbTag};
|
||||
use crate::errors::DatabaseError;
|
||||
use crate::types::Weekday;
|
||||
use crate::utils;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct DbRelay {
|
||||
|
@ -162,4 +165,14 @@ impl DbRelay {
|
|||
.await?
|
||||
.ok_or(DatabaseError::NotFound)
|
||||
}
|
||||
|
||||
pub async fn get_active_schedule(
|
||||
&self,
|
||||
conn: &mut PoolConnection<Sqlite>,
|
||||
) -> Result<DbSchedule, DatabaseError> {
|
||||
let weekday = utils::get_weekday();
|
||||
DbJunctionRelaySchedule::get_schedule(conn, &self, weekday as Weekday)
|
||||
.await?
|
||||
.ok_or(DatabaseError::NotFound)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue