use crate::tui::windows::{ConfirmWnd, MainWnd, WndId}; use crate::CLIENT; use u_lib::models::{Agent, AssignedJob, JobMeta}; use u_lib::UResult; use uuid::Uuid; pub trait Id { fn id(&self) -> T; } #[macro_export] macro_rules! impl_id { ($id_type:tt => $($type:tt),+) => { $( impl Id<$id_type> for $type { fn id(&self) -> $id_type { self.id } })+ }; } impl_id!(Uuid => Agent, JobMeta, AssignedJob); impl_id!(WndId => MainWnd, ConfirmWnd); #[async_trait] pub trait CRUD: Id where Self: Sized, { async fn read() -> UResult>; async fn delete(uid: Uuid) -> UResult { CLIENT.del(Some(uid)).await } //TODO: other crud } #[async_trait] impl CRUD for Agent { async fn read() -> UResult> { CLIENT.get_agents(None).await.map(|r| r.into_builtin_vec()) } } #[async_trait] impl CRUD for AssignedJob { async fn read() -> UResult> { CLIENT .get_agent_jobs(None) .await .map(|r| r.into_builtin_vec()) } } #[async_trait] impl CRUD for JobMeta { async fn read() -> UResult> { CLIENT.get_jobs(None).await.map(|r| r.into_builtin_vec()) } }