controller/emgauwa-lib/src/return_models.rs

33 lines
693 B
Rust

use crate::db::schedules::Schedule;
use futures::executor;
use serde::Serialize;
use sqlx::pool::PoolConnection;
use sqlx::Sqlite;
#[derive(Debug, Serialize)]
pub struct ReturnSchedule {
#[serde(flatten)]
pub schedule: Schedule,
pub tags: Vec<String>,
}
impl ReturnSchedule {
pub fn load_tags(&mut self, conn: &mut PoolConnection<Sqlite>) {
self.tags = executor::block_on(self.schedule.get_tags(conn)).unwrap();
}
}
impl From<Schedule> for ReturnSchedule {
fn from(schedule: Schedule) -> Self {
ReturnSchedule {
schedule,
tags: vec![],
}
}
}
impl From<&Schedule> for ReturnSchedule {
fn from(schedule: &Schedule) -> Self {
ReturnSchedule::from(schedule.clone())
}
}