feat: add fields endpoint with get, batch-get, and list methods
Implement Field model supporting base fields and polymorphic variants (list, formula, reference fields via optional properties). Add get_field, batch_get_fields, and list_fields endpoint methods with tests covering basic fields, list-type fields, batch retrieval, pagination, and not-found scenarios.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
use reqwest::Method;
|
||||
|
||||
use crate::client::OnspringClient;
|
||||
use crate::error::Result;
|
||||
use crate::models::{CollectionResponse, Field, PagedResponse, PagingRequest};
|
||||
|
||||
impl OnspringClient {
|
||||
/// Gets a field by its identifier.
|
||||
pub async fn get_field(&self, field_id: i32) -> Result<Field> {
|
||||
let path = format!("/Fields/id/{}", field_id);
|
||||
self.request(Method::GET, &path, &[], Option::<&()>::None)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Gets up to 100 fields by their identifiers.
|
||||
pub async fn batch_get_fields(&self, ids: &[i32]) -> Result<CollectionResponse<Field>> {
|
||||
self.request(Method::POST, "/Fields/batch-get", &[], Some(&ids))
|
||||
.await
|
||||
}
|
||||
|
||||
/// Gets a paginated list of fields for a given application.
|
||||
pub async fn list_fields(
|
||||
&self,
|
||||
app_id: i32,
|
||||
paging: Option<PagingRequest>,
|
||||
) -> Result<PagedResponse<Field>> {
|
||||
let path = format!("/Fields/appId/{}", app_id);
|
||||
let mut query = Vec::new();
|
||||
if let Some(p) = paging {
|
||||
query.push(("PageNumber", p.page_number.to_string()));
|
||||
query.push(("PageSize", p.page_size.to_string()));
|
||||
}
|
||||
let query_refs: Vec<(&str, String)> = query.iter().map(|(k, v)| (*k, v.clone())).collect();
|
||||
self.request(Method::GET, &path, &query_refs, Option::<&()>::None)
|
||||
.await
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,3 @@
|
||||
mod apps;
|
||||
mod fields;
|
||||
mod ping;
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
use serde::Deserialize;
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::enums::{FormulaOutputType, Multiplicity};
|
||||
|
||||
/// Represents a field in an Onspring application.
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Field {
|
||||
pub id: i32,
|
||||
pub app_id: i32,
|
||||
pub name: Option<String>,
|
||||
#[serde(rename = "type")]
|
||||
pub field_type: Option<String>,
|
||||
pub status: Option<String>,
|
||||
pub is_required: bool,
|
||||
pub is_unique: bool,
|
||||
pub multiplicity: Option<Multiplicity>,
|
||||
pub list_id: Option<i32>,
|
||||
pub values: Option<Vec<ListFieldValue>>,
|
||||
#[serde(rename = "outputType")]
|
||||
pub output_type: Option<FormulaOutputType>,
|
||||
pub referenced_app_id: Option<i32>,
|
||||
}
|
||||
|
||||
/// Represents a value in a list field.
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ListFieldValue {
|
||||
pub id: Uuid,
|
||||
pub name: String,
|
||||
pub sort_order: i32,
|
||||
pub numeric_value: Option<f64>,
|
||||
pub color: Option<String>,
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
mod app;
|
||||
mod enums;
|
||||
mod field;
|
||||
mod paging;
|
||||
|
||||
pub use app::*;
|
||||
pub use enums::*;
|
||||
pub use field::*;
|
||||
pub use paging::*;
|
||||
|
||||
Reference in New Issue
Block a user