feat: add reports endpoint with get report and list reports methods
Implement ReportInfo, ReportData, and ReportRow models. Add get_report (with optional data format and data type params) and list_reports (paginated) methods. Tests cover report data retrieval, format parameters, listing reports by app, and not-found error.
This commit is contained in:
@@ -4,3 +4,4 @@ mod files;
|
||||
mod lists;
|
||||
mod ping;
|
||||
mod records;
|
||||
mod reports;
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
use reqwest::Method;
|
||||
|
||||
use crate::client::OnspringClient;
|
||||
use crate::error::Result;
|
||||
use crate::models::{
|
||||
DataFormat, PagedResponse, PagingRequest, ReportData, ReportDataType, ReportInfo,
|
||||
};
|
||||
|
||||
impl OnspringClient {
|
||||
/// Gets report data by report ID.
|
||||
pub async fn get_report(
|
||||
&self,
|
||||
report_id: i32,
|
||||
data_format: Option<DataFormat>,
|
||||
data_type: Option<ReportDataType>,
|
||||
) -> Result<ReportData> {
|
||||
let path = format!("/Reports/id/{}", report_id);
|
||||
let mut query = Vec::new();
|
||||
if let Some(fmt) = data_format {
|
||||
query.push(("apiDataFormat", format!("{:?}", fmt)));
|
||||
}
|
||||
if let Some(dt) = data_type {
|
||||
query.push(("dataType", format!("{:?}", dt)));
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
/// Gets a paginated list of reports for a given application.
|
||||
pub async fn list_reports(
|
||||
&self,
|
||||
app_id: i32,
|
||||
paging: Option<PagingRequest>,
|
||||
) -> Result<PagedResponse<ReportInfo>> {
|
||||
let path = format!("/Reports/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
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ pub mod file;
|
||||
pub mod list;
|
||||
mod paging;
|
||||
pub mod record;
|
||||
mod report;
|
||||
|
||||
pub use app::*;
|
||||
pub use enums::*;
|
||||
@@ -13,3 +14,4 @@ pub use file::*;
|
||||
pub use list::*;
|
||||
pub use paging::*;
|
||||
pub use record::*;
|
||||
pub use report::*;
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
use serde::Deserialize;
|
||||
|
||||
/// Represents a report associated to an app (used in list responses).
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ReportInfo {
|
||||
pub app_id: i32,
|
||||
pub id: i32,
|
||||
pub name: Option<String>,
|
||||
pub description: Option<String>,
|
||||
}
|
||||
|
||||
/// Represents the data returned by a report.
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ReportData {
|
||||
pub columns: Option<Vec<String>>,
|
||||
pub rows: Option<Vec<ReportRow>>,
|
||||
}
|
||||
|
||||
/// Represents a single row in a report.
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ReportRow {
|
||||
pub record_id: Option<i32>,
|
||||
pub cells: Option<Vec<serde_json::Value>>,
|
||||
}
|
||||
Reference in New Issue
Block a user