diff --git a/src/api/mod.rs b/src/api/mod.rs index 5ac9f38..a73afda 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -247,7 +247,23 @@ impl Api { P: AsRef + Display, T: DeserializeOwned, { - self.execute_with_headers(method, path, body, vec![]).await + self.execute_with_params_and_headers(method, path, body, vec![], vec![]) + .await + } + + async fn execute_with_params( + &self, + method: Method, + path: P, + body: Option, + params: Vec<(String, String)>, + ) -> Result, Error> + where + P: AsRef + Display, + T: DeserializeOwned, + { + self.execute_with_params_and_headers(method, path, body, params, vec![]) + .await } async fn execute_with_headers( @@ -257,6 +273,22 @@ impl Api { body: Option, headers: Vec<(String, String)>, ) -> Result, Error> + where + P: AsRef + Display, + T: DeserializeOwned, + { + self.execute_with_params_and_headers(method, path, body, vec![], headers) + .await + } + + async fn execute_with_params_and_headers( + &self, + method: Method, + path: P, + body: Option, + params: Vec<(String, String)>, + headers: Vec<(String, String)>, + ) -> Result, Error> where P: AsRef + Display, T: DeserializeOwned, @@ -273,6 +305,7 @@ impl Api { let req_builder = self .http .request(method.clone(), endpoint) + .query(¶ms) .header("Authorization", format!("Token {}", &self.api_key)) .headers(hmap); diff --git a/src/api/products_v2.rs b/src/api/products_v2.rs index e78c7e8..7f4b054 100644 --- a/src/api/products_v2.rs +++ b/src/api/products_v2.rs @@ -8,9 +8,9 @@ use snafu::ResultExt; #[derive(Debug, Deserialize, Serialize)] pub struct ProductV2 { + pub archived: bool, pub inserted_at: String, pub name: String, - pub organization_prn: String, pub prn: String, pub updated_at: String, } @@ -56,6 +56,9 @@ pub struct UpdateProductV2Params { #[serde(skip_serializing_if = "Option::is_none")] #[serde(default)] pub name: Option, + #[serde(skip_serializing_if = "Option::is_none")] + #[serde(default)] + pub archived: Option, } #[derive(Debug, Deserialize, Serialize)] @@ -96,13 +99,21 @@ impl<'a> ProductsV2Api<'a> { &'a self, params: ListProductsV2Params, ) -> Result, Error> { - let search_string = params.search; + let mut query_params = vec![("search".to_string(), params.search)]; + + if let Some(limit) = params.limit { + query_params.push(("limit".to_string(), limit.to_string())) + } + if let Some(order) = params.order { + query_params.push(("order".to_string(), order)) + } + + if let Some(page) = params.page { + query_params.push(("page".to_string(), page)) + } + self.0 - .execute( - Method::GET, - format!("/products?search={search_string}"), - None, - ) + .execute_with_params(Method::GET, "/products".to_string(), None, query_params) .await } diff --git a/tests/fixtures/products-v2-create-201.json b/tests/fixtures/products-v2-create-201.json index 1fbd2f0..66e695c 100644 --- a/tests/fixtures/products-v2-create-201.json +++ b/tests/fixtures/products-v2-create-201.json @@ -1,8 +1,8 @@ { "product": { + "archived": false, "inserted_at": "2000-01-01T00:00:00Z", "name": "name", - "organization_prn": "organization_prn", "prn": "prn", "updated_at": "2000-01-01T00:00:00Z" } diff --git a/tests/fixtures/products-v2-get-200.json b/tests/fixtures/products-v2-get-200.json index 1fbd2f0..66e695c 100644 --- a/tests/fixtures/products-v2-get-200.json +++ b/tests/fixtures/products-v2-get-200.json @@ -1,8 +1,8 @@ { "product": { + "archived": false, "inserted_at": "2000-01-01T00:00:00Z", "name": "name", - "organization_prn": "organization_prn", "prn": "prn", "updated_at": "2000-01-01T00:00:00Z" } diff --git a/tests/fixtures/products-v2-update-200.json b/tests/fixtures/products-v2-update-200.json index 1fbd2f0..aca6906 100644 --- a/tests/fixtures/products-v2-update-200.json +++ b/tests/fixtures/products-v2-update-200.json @@ -1,8 +1,8 @@ { "product": { + "archived": true, "inserted_at": "2000-01-01T00:00:00Z", "name": "name", - "organization_prn": "organization_prn", "prn": "prn", "updated_at": "2000-01-01T00:00:00Z" } diff --git a/tests/products_v2.rs b/tests/products_v2.rs index 0b1105f..c75afad 100644 --- a/tests/products_v2.rs +++ b/tests/products_v2.rs @@ -33,10 +33,6 @@ async fn create_product() { match api.products_v2().create(params).await.unwrap() { Some(product) => { assert_eq!(product.product.name, expected_name.to_string()); - assert_eq!( - product.product.organization_prn, - expected_organization_prn.to_string() - ); } _ => panic!(), } @@ -47,7 +43,6 @@ async fn create_product() { #[tokio::test] async fn get_product() { let expected_name = "name"; - let expected_organization_prn = "organization_prn"; let expected_prn = "prn"; let api = Api::new(ApiOptions { @@ -69,10 +64,6 @@ async fn get_product() { match api.products_v2().get(params).await.unwrap() { Some(product) => { assert_eq!(product.product.name, expected_name.to_string()); - assert_eq!( - product.product.organization_prn, - expected_organization_prn.to_string() - ); } _ => panic!(), } @@ -82,8 +73,8 @@ async fn get_product() { #[tokio::test] async fn update_product() { + let expected_archived = true; let expected_name = "name"; - let expected_organization_prn = "organization_prn"; let expected_prn = "prn"; let api = Api::new(ApiOptions { @@ -101,15 +92,13 @@ async fn update_product() { let params = UpdateProductV2Params { prn: expected_prn.to_string(), name: Some(expected_name.to_string()), + archived: Some(true), }; match api.products_v2().update(params).await.unwrap() { Some(product) => { assert_eq!(product.product.name, expected_name.to_string()); - assert_eq!( - product.product.organization_prn, - expected_organization_prn.to_string() - ); + assert_eq!(product.product.archived, expected_archived); } _ => panic!(), }