Skip to content

Commit

Permalink
new trait operations
Browse files Browse the repository at this point in the history
  • Loading branch information
rruckley committed Mar 30, 2024
1 parent 0bad60b commit 972ec87
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
pub mod tmf;
pub mod common;

use common::tmf_error::TMFError;
use tmf::tmf620::TMF620;
use tmf::tmf622::TMF622;

use tmflib::HasId;

/// Fields for filtering output
#[derive(Clone, Default, Debug)]
pub struct QueryOptions {
Expand Down Expand Up @@ -57,6 +60,40 @@ impl From<QueryOptions> for String {
}
}

pub trait Operations {
type TMF : HasId;

/// Get a specific tmf object by Id
/// ```
/// # use tmf_client::TMFClient;
/// let categories = TMFClient::new("http://localhost:8000")
/// .tmf620()
/// .category()
/// .get("ID123");
/// ```
fn get(&self, id : impl Into<String>) -> Result<Vec<Self::TMF>,TMFError>;
/// Get a list of tmf objects applying optional filter
/// ```
/// # use tmf_client::TMFClient;
/// let categories = TMFClient::new("http://localhost:8000")
/// .tmf620()
/// .category()
/// .list(None);
/// ```
fn list(&self, filter : Option<QueryOptions>) -> Result<Vec<Self::TMF>,TMFError>;
fn create(&self, item : Self::TMF) -> Result<Self::TMF,TMFError>;
fn update(&self, id : impl Into<String>, patch : Self::TMF) -> Result<Self::TMF,TMFError>;
/// Delete a specific tmf object by Id
/// ```
/// # use tmf_client::TMFClient;
/// let categories = TMFClient::new("http://localhost:8000")
/// .tmf620()
/// .category()
/// .get("ID123");
/// ```
fn delete(&self, id : impl Into<String>) -> Result<Self::TMF,TMFError>;
}

pub struct TMFClient {
host : String,
tmf620 : Option<TMF620>,
Expand Down

0 comments on commit 972ec87

Please sign in to comment.