You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.2 KiB
61 lines
1.2 KiB
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<T> { |
|
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<Uuid> |
|
where |
|
Self: Sized, |
|
{ |
|
async fn read() -> UResult<Vec<Self>>; |
|
|
|
async fn delete(uid: Uuid) -> UResult<i32> { |
|
CLIENT.del(Some(uid)).await |
|
} |
|
//TODO: other crud |
|
} |
|
|
|
#[async_trait] |
|
impl CRUD for Agent { |
|
async fn read() -> UResult<Vec<Agent>> { |
|
CLIENT.get_agents(None).await.map(|r| r.into_builtin_vec()) |
|
} |
|
} |
|
|
|
#[async_trait] |
|
impl CRUD for AssignedJob { |
|
async fn read() -> UResult<Vec<AssignedJob>> { |
|
CLIENT |
|
.get_agent_jobs(None) |
|
.await |
|
.map(|r| r.into_builtin_vec()) |
|
} |
|
} |
|
|
|
#[async_trait] |
|
impl CRUD for JobMeta { |
|
async fn read() -> UResult<Vec<JobMeta>> { |
|
CLIENT.get_jobs(None).await.map(|r| r.into_builtin_vec()) |
|
} |
|
}
|
|
|