Skip to main content

onspring/endpoints/
fields.rs

1use reqwest::Method;
2
3use crate::client::OnspringClient;
4use crate::error::Result;
5use crate::models::{CollectionResponse, Field, PagedResponse, PagingRequest};
6
7impl OnspringClient {
8  /// Gets a field by its identifier.
9  pub async fn get_field(&self, field_id: i32) -> Result<Field> {
10    let path = format!("/Fields/id/{}", field_id);
11    self
12      .request(Method::GET, &path, &[], Option::<&()>::None)
13      .await
14  }
15
16  /// Gets up to 100 fields by their identifiers.
17  pub async fn batch_get_fields(&self, ids: &[i32]) -> Result<CollectionResponse<Field>> {
18    self
19      .request(Method::POST, "/Fields/batch-get", &[], Some(&ids))
20      .await
21  }
22
23  /// Gets a paginated list of fields for a given application.
24  pub async fn list_fields(
25    &self,
26    app_id: i32,
27    paging: Option<PagingRequest>,
28  ) -> Result<PagedResponse<Field>> {
29    let path = format!("/Fields/appId/{}", app_id);
30    let mut query = Vec::new();
31    if let Some(p) = paging {
32      query.push(("PageNumber", p.page_number.to_string()));
33      query.push(("PageSize", p.page_size.to_string()));
34    }
35    let query_refs: Vec<(&str, String)> = query.iter().map(|(k, v)| (*k, v.clone())).collect();
36    self
37      .request(Method::GET, &path, &query_refs, Option::<&()>::None)
38      .await
39  }
40}