use futures::executor; use serde::Serialize; use sqlx::pool::PoolConnection; use sqlx::Sqlite; use crate::db::models::Schedule; use crate::db::schedules::get_schedule_tags; #[derive(Debug, Serialize)] pub struct ReturnSchedule { #[serde(flatten)] pub schedule: Schedule, pub tags: Vec, } impl ReturnSchedule { pub fn load_tags(&mut self, conn: &mut PoolConnection) { self.tags = executor::block_on(get_schedule_tags(conn, &self.schedule)).unwrap(); } } impl From 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()) } }