feat: added reports command and added support for json config
This commit is contained in:
1 parent
c83708a727
commit
df07eec5fa
7 files changed
+1124
-13
No files matched your search
+56
-2
@@ -3,8 +3,8 @@ use std::io::Write;
|
||||
use chrono::{DateTime, Utc};
|
||||
use onspring::{
|
||||
App, CollectionResponse, CreatedWithIdResponse, Field, FileInfo, FormulaOutputType,
|
||||
ListFieldValue, Multiplicity, PagedResponse, Record, RecordFieldValue, SaveListItemResponse,
|
||||
SaveRecordResponse, ValueType,
|
||||
ListFieldValue, Multiplicity, PagedResponse, Record, RecordFieldValue, ReportData, ReportInfo,
|
||||
ReportRow, SaveListItemResponse, SaveRecordResponse, ValueType,
|
||||
};
|
||||
use serde::Serialize;
|
||||
use uuid::Uuid;
|
||||
@@ -263,6 +263,60 @@ impl From<SaveListItemResponse> for SaveListItemResponseOutput {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ReportInfoOutput {
|
||||
pub app_id: i32,
|
||||
pub id: i32,
|
||||
pub name: Option<String>,
|
||||
pub description: Option<String>,
|
||||
}
|
||||
|
||||
impl From<ReportInfo> for ReportInfoOutput {
|
||||
fn from(value: ReportInfo) -> Self {
|
||||
Self {
|
||||
app_id: value.app_id,
|
||||
id: value.id,
|
||||
name: value.name,
|
||||
description: value.description,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ReportRowOutput {
|
||||
pub record_id: Option<i32>,
|
||||
pub cells: Option<Vec<serde_json::Value>>,
|
||||
}
|
||||
|
||||
impl From<ReportRow> for ReportRowOutput {
|
||||
fn from(value: ReportRow) -> Self {
|
||||
Self {
|
||||
record_id: value.record_id,
|
||||
cells: value.cells,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ReportDataOutput {
|
||||
pub columns: Option<Vec<String>>,
|
||||
pub rows: Option<Vec<ReportRowOutput>>,
|
||||
}
|
||||
|
||||
impl From<ReportData> for ReportDataOutput {
|
||||
fn from(value: ReportData) -> Self {
|
||||
Self {
|
||||
columns: value.columns,
|
||||
rows: value
|
||||
.rows
|
||||
.map(|rows| rows.into_iter().map(ReportRowOutput::from).collect()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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