Skip to main content

onspring/models/
record.rs

1use std::collections::HashMap;
2
3use serde::{Deserialize, Serialize};
4
5use super::enums::{DataFormat, ValueType};
6
7/// Represents a record in an Onspring application.
8#[derive(Debug, Clone, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct Record {
11  pub app_id: i32,
12  pub record_id: i32,
13  pub field_data: Option<Vec<RecordFieldValue>>,
14}
15
16/// Represents a single field value within a record.
17#[derive(Debug, Clone, Deserialize)]
18#[serde(rename_all = "camelCase")]
19pub struct RecordFieldValue {
20  #[serde(rename = "type")]
21  pub value_type: ValueType,
22  pub field_id: i32,
23  pub value: serde_json::Value,
24}
25
26/// Request to create or update a record.
27#[derive(Debug, Clone, Serialize)]
28#[serde(rename_all = "camelCase")]
29pub struct SaveRecordRequest {
30  pub app_id: i32,
31  #[serde(skip_serializing_if = "Option::is_none")]
32  pub record_id: Option<i32>,
33  pub fields: HashMap<String, serde_json::Value>,
34}
35
36/// Response from saving a record.
37#[derive(Debug, Clone, Deserialize)]
38#[serde(rename_all = "camelCase")]
39pub struct SaveRecordResponse {
40  pub id: i32,
41  pub warnings: Option<Vec<String>>,
42}
43
44/// Request to query records with a filter.
45#[derive(Debug, Clone, Serialize)]
46#[serde(rename_all = "camelCase")]
47pub struct QueryRecordsRequest {
48  pub app_id: i32,
49  pub filter: String,
50  #[serde(skip_serializing_if = "Option::is_none")]
51  pub field_ids: Option<Vec<i32>>,
52  #[serde(skip_serializing_if = "Option::is_none")]
53  pub data_format: Option<DataFormat>,
54}
55
56/// Request to get a batch of records.
57#[derive(Debug, Clone, Serialize)]
58#[serde(rename_all = "camelCase")]
59pub struct BatchGetRecordsRequest {
60  pub app_id: i32,
61  pub record_ids: Vec<i32>,
62  #[serde(skip_serializing_if = "Option::is_none")]
63  pub field_ids: Option<Vec<i32>>,
64  #[serde(skip_serializing_if = "Option::is_none")]
65  pub data_format: Option<DataFormat>,
66}
67
68/// Request to delete a batch of records.
69#[derive(Debug, Clone, Serialize)]
70#[serde(rename_all = "camelCase")]
71pub struct BatchDeleteRecordsRequest {
72  pub app_id: i32,
73  pub record_ids: Vec<i32>,
74}