diff --git a/src/api/groups.rs b/src/api/groups.rs index ebfb6d7..ea7474a 100644 --- a/src/api/groups.rs +++ b/src/api/groups.rs @@ -5,24 +5,10 @@ use serde::{Deserialize, Serialize}; use schemars::JsonSchema; use crate::api::{ - DomainObject, DomainType + DomainCollection, DomainObject, DomainType, domain_client }; use crate::{ApiClient, Client, Result}; -impl Client { - pub fn host_group_api(&self) -> ApiClient { - self.into() - } - - pub fn service_group_api(&self) -> ApiClient { - self.into() - } - - pub fn contact_group_api(&self) -> ApiClient { - self.into() - } -} - #[derive(Debug, Clone, Serialize, Deserialize)] #[cfg_attr(feature = "schemars", derive(JsonSchema))] pub struct Group { @@ -44,10 +30,11 @@ impl From> for Group { macro_rules! domain_group { - ($id:ident, $typ:expr) => { + ($id:ident, $typ:expr, $func:ident) => { #[derive(Debug, Clone, Serialize, Deserialize)] #[cfg_attr(feature = "schemars", derive(JsonSchema))] pub struct $id(Group); + domain_client!($id, $func); impl Deref for $id { type Target = Group; @@ -69,12 +56,6 @@ macro_rules! domain_group { } } - impl From<&Client> for ApiClient<$id> { - fn from(value: &Client) -> Self { - Self::new(value) - } - } - impl ApiClient<$id> { pub async fn create(&self, group: &$id) -> Result<()> { self.inner.create($typ, group, &()).await @@ -100,12 +81,13 @@ macro_rules! domain_group { self.inner.bulk_create($typ, entries, &()).await } pub async fn bulk_read(&self) -> Result> { - let entries: Vec> = + let collection: DomainCollection = self.inner.bulk_read($typ, &()).await?; - let objects = entries.into_iter() + let groups = collection.value + .into_iter() .map($id::from) .collect(); - Ok(objects) + Ok(groups) } pub async fn bulk_update(&self, entries: &[Group]) -> Result<()> { #[derive(Serialize)] @@ -140,6 +122,6 @@ macro_rules! domain_group { } } -domain_group!(HostGroup, DomainType::HostGroupConfig); -domain_group!(ServiceGroup, DomainType::ServiceGroupConfig); -domain_group!(ContactGroup, DomainType::ContactGroupConfig); +domain_group!(HostGroup, DomainType::HostGroupConfig, host_group_api); +domain_group!(ServiceGroup, DomainType::ServiceGroupConfig, service_group_api); +domain_group!(ContactGroup, DomainType::ContactGroupConfig, contact_group_api);