use std::sync::Arc;
use crate::error::{map_manager_err, ManagerError};
use crate::gen::manager::apis::configuration::Configuration;
use crate::gen::manager::apis::routing_api as api;
use crate::gen::manager::models;
use crate::http::collect_all;
use crate::retry::{with_retry, RetryPolicy};
pub struct RoutingResource {
pub(crate) cfg: Arc<Configuration>,
pub(crate) retry: RetryPolicy,
}
impl RoutingResource {
pub async fn list_all(&self) -> Result<Vec<models::Routing>, ManagerError> {
collect_all(&self.retry, map_manager_err, |page| async move {
let r = api::list_routings(self.cfg.as_ref(), Some(page), None).await?;
Ok((r.items, r.pagination.pages, r.pagination.current))
})
.await
}
pub async fn create(
&self,
body: models::RestCreateRouting,
) -> Result<models::RoutingItemResponse, ManagerError> {
with_retry(&self.retry, false, || {
api::create_routing(self.cfg.as_ref(), body.clone())
})
.await
.map_err(map_manager_err)
}
pub async fn get(&self, id: &str) -> Result<models::RoutingItemResponse, ManagerError> {
with_retry(&self.retry, true, || {
api::get_routing(self.cfg.as_ref(), id)
})
.await
.map_err(map_manager_err)
}
pub async fn update(
&self,
id: &str,
body: models::RestUpdateRouting,
) -> Result<models::RoutingItemResponse, ManagerError> {
with_retry(&self.retry, false, || {
api::update_routing(self.cfg.as_ref(), id, body.clone())
})
.await
.map_err(map_manager_err)
}
pub async fn delete(&self, id: &str) -> Result<(), ManagerError> {
with_retry(&self.retry, false, || {
api::delete_routing(self.cfg.as_ref(), id)
})
.await
.map_err(map_manager_err)?;
Ok(())
}
}