From 3ab4c018b34e47e501f9d1e21d2fb7e0c126b98e Mon Sep 17 00:00:00 2001 From: Ryan Date: Sat, 30 Mar 2024 12:24:06 +1100 Subject: [PATCH] implement trait --- src/tmf/tmf620.rs | 130 +++++++++++++++++++++++++++++++++------------- 1 file changed, 94 insertions(+), 36 deletions(-) diff --git a/src/tmf/tmf620.rs b/src/tmf/tmf620.rs index f588523..fed6380 100644 --- a/src/tmf/tmf620.rs +++ b/src/tmf/tmf620.rs @@ -1,5 +1,6 @@ //! TMF620 Product Catalogue + use tmflib::tmf620::catalog::Catalog; use tmflib::tmf620::category::Category; use tmflib::tmf620::product_offering::ProductOffering; @@ -9,7 +10,7 @@ use tmflib::Uri; use super::{get_tmf,list_tmf}; use crate::common::tmf_error::TMFError; -use crate::QueryOptions; +use crate::{QueryOptions,Operations}; /// TMF620 Category API calls #[derive(Clone,Default,Debug)] @@ -26,19 +27,32 @@ impl TMF620Category { pub fn get(&self, _id : impl Into) -> Result,TMFError> { get_tmf(self.host.clone(),_id.into()) } - /// Get a list of catalogs applying optional filter - /// ``` - /// # use tmf_client::TMFClient; - /// let categories = TMFClient::new("http://localhost:8000") - /// .tmf620() - /// .category() - /// .list(None); - /// ``` + pub fn list(&self, filter : Option) -> Result,TMFError> { list_tmf(self.host.clone(),filter) } } +impl Operations for TMF620Category { + type TMF = Category; + + fn create(&self, _item : Self::TMF) -> Result { + Err(TMFError::from("Not implemented")) + } + fn delete(&self, _id : impl Into) -> Result { + Err(TMFError::from("Not implemented")) + } + fn get(&self, id : impl Into) -> Result,TMFError> { + get_tmf(self.host.clone(),id.into()) + } + fn list(&self, filter : Option) -> Result,TMFError> { + list_tmf(self.host.clone(),filter) + } + fn update(&self, _id : impl Into, _patch : Self::TMF) -> Result { + Err(TMFError::from("Not implemented")) + } +} + /// TMF620 Catalog API calls #[derive(Clone,Default,Debug)] pub struct TMF620Catalog { @@ -50,16 +64,30 @@ impl TMF620Catalog { pub fn new(host : Uri) -> TMF620Catalog { TMF620Catalog { host } } - /// Get a single catalog entry - pub fn get(&self, _id : impl Into) -> Result,TMFError> { - get_tmf(self.host.clone(),_id.into()) +} + +impl Operations for TMF620Catalog { + type TMF = Catalog; + + fn create(&self, _item : Self::TMF) -> Result { + Err(TMFError::from("Not implemented")) } - /// Get a list of catalogs applying optional filter - pub fn list(&self, filter : Option) -> Result,TMFError> { - list_tmf(self.host.clone(),filter) + fn delete(&self, _id : impl Into) -> Result { + Err(TMFError::from("Not implemented")) + } + fn get(&self, id : impl Into) -> Result,TMFError> { + get_tmf(self.host.clone(),id.into()) + } + fn list(&self, filter : Option) -> Result,TMFError> { + list_tmf(self.host.clone(),filter) + } + fn update(&self, _id : impl Into, _patch : Self::TMF) -> Result { + Err(TMFError::from("Not implemented")) } } + + /// TMF620 ProductOffering API calls #[derive(Clone,Default,Debug)] pub struct TMF620ProductOffering { @@ -71,15 +99,25 @@ impl TMF620ProductOffering { pub fn new(host : Uri) -> TMF620ProductOffering { TMF620ProductOffering { host } } +} - /// Get a single product offering - pub fn get(&self, _id : impl Into) -> Result,TMFError> { - get_tmf(self.host.clone(),_id.into()) - } +impl Operations for TMF620ProductOffering { + type TMF = ProductOffering; - /// Get a list of catalogs applying optional filter - pub fn list(&self, filter : Option) -> Result,TMFError> { - list_tmf(self.host.clone(),filter) + fn create(&self, _item : Self::TMF) -> Result { + Err(TMFError::from("Not implemented")) + } + fn delete(&self, _id : impl Into) -> Result { + Err(TMFError::from("Not implemented")) + } + fn get(&self, id : impl Into) -> Result,TMFError> { + get_tmf(self.host.clone(),id.into()) + } + fn list(&self, filter : Option) -> Result,TMFError> { + list_tmf(self.host.clone(),filter) + } + fn update(&self, _id : impl Into, _patch : Self::TMF) -> Result { + Err(TMFError::from("Not implemented")) } } @@ -94,15 +132,25 @@ impl TMF620ProductOfferingPrice { pub fn new(host : Uri) -> TMF620ProductOfferingPrice { TMF620ProductOfferingPrice { host } } +} - /// Get a single product offering - pub fn get(&self, _id : impl Into) -> Result,TMFError> { - get_tmf(self.host.clone(),_id.into()) - } +impl Operations for TMF620ProductOfferingPrice { + type TMF = ProductOfferingPrice; - /// Get a list of catalogs applying optional filter - pub fn list(&self, filter : Option) -> Result,TMFError> { - list_tmf(self.host.clone(),filter) + fn create(&self, _item : Self::TMF) -> Result { + Err(TMFError::from("Not implemented")) + } + fn delete(&self, _id : impl Into) -> Result { + Err(TMFError::from("Not implemented")) + } + fn get(&self, id : impl Into) -> Result,TMFError> { + get_tmf(self.host.clone(),id.into()) + } + fn list(&self, filter : Option) -> Result,TMFError> { + list_tmf(self.host.clone(),filter) + } + fn update(&self, _id : impl Into, _patch : Self::TMF) -> Result { + Err(TMFError::from("Not implemented")) } } @@ -117,15 +165,25 @@ impl TMF620ProductSpecification { pub fn new(host : Uri) -> TMF620ProductSpecification { TMF620ProductSpecification { host } } +} - /// Get a single product offering - pub fn get(&self, _id : impl Into) -> Result,TMFError> { - get_tmf(self.host.clone(),_id.into()) - } +impl Operations for TMF620ProductSpecification { + type TMF = ProductSpecification; - /// Get a list of catalogs applying optional filter - pub fn list(&self, filter : Option) -> Result,TMFError> { - list_tmf(self.host.clone(),filter) + fn create(&self, _item : Self::TMF) -> Result { + Err(TMFError::from("Not implemented")) + } + fn delete(&self, _id : impl Into) -> Result { + Err(TMFError::from("Not implemented")) + } + fn get(&self, id : impl Into) -> Result,TMFError> { + get_tmf(self.host.clone(),id.into()) + } + fn list(&self, filter : Option) -> Result,TMFError> { + list_tmf(self.host.clone(),filter) + } + fn update(&self, _id : impl Into, _patch : Self::TMF) -> Result { + Err(TMFError::from("Not implemented")) } }