feat: implement record commands
This commit is contained in:
1 parent
54346ff20f
commit
56b5abc1d1
6 files changed
+2101
-15
No files matched your search
@@ -2,6 +2,7 @@ use std::io::Write;
|
||||
|
||||
use onspring::{
|
||||
App, CollectionResponse, Field, FormulaOutputType, ListFieldValue, Multiplicity, PagedResponse,
|
||||
Record, RecordFieldValue, SaveRecordResponse, ValueType,
|
||||
};
|
||||
use serde::Serialize;
|
||||
use uuid::Uuid;
|
||||
@@ -152,6 +153,61 @@ impl From<Field> for FieldOutput {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct RecordFieldValueOutput {
|
||||
#[serde(rename = "type")]
|
||||
pub value_type: ValueType,
|
||||
pub field_id: i32,
|
||||
pub value: serde_json::Value,
|
||||
}
|
||||
|
||||
impl From<RecordFieldValue> for RecordFieldValueOutput {
|
||||
fn from(value: RecordFieldValue) -> Self {
|
||||
Self {
|
||||
value_type: value.value_type,
|
||||
field_id: value.field_id,
|
||||
value: value.value,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct RecordOutput {
|
||||
pub app_id: i32,
|
||||
pub record_id: i32,
|
||||
pub field_data: Option<Vec<RecordFieldValueOutput>>,
|
||||
}
|
||||
|
||||
impl From<Record> for RecordOutput {
|
||||
fn from(value: Record) -> Self {
|
||||
Self {
|
||||
app_id: value.app_id,
|
||||
record_id: value.record_id,
|
||||
field_data: value
|
||||
.field_data
|
||||
.map(|fields| fields.into_iter().map(RecordFieldValueOutput::from).collect()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SaveRecordResponseOutput {
|
||||
pub id: i32,
|
||||
pub warnings: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
impl From<SaveRecordResponse> for SaveRecordResponseOutput {
|
||||
fn from(value: SaveRecordResponse) -> Self {
|
||||
Self {
|
||||
id: value.id,
|
||||
warnings: value.warnings,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render_json<T: Serialize>(value: &T, pretty: bool) -> CliResult<String> {
|
||||
if pretty {
|
||||
serde_json::to_string_pretty(value).map_err(|_| CliError::runtime("Failed to serialize output"))
|
||||
|
||||
Reference in new issue
Block a user