resourcespace_client/api/system.rs
1use serde::Serialize;
2use serde_with::skip_serializing_none;
3use validator::Validate;
4
5use crate::client::Client;
6use crate::error::RsError;
7
8/// Sub-API for system endpoints.
9#[derive(Debug)]
10pub struct SystemApi<'a> {
11 client: &'a Client,
12}
13
14impl<'a> SystemApi<'a> {
15 pub(crate) fn new(client: &'a Client) -> Self {
16 Self { client }
17 }
18
19 /// Get system status - healthcheck information.
20 ///
21 /// ## Arguments
22 /// `None`
23 ///
24 /// ## Returns
25 /// Returns back system status information (configuration dependant - e.g mysql_log_transactions).
26 ///
27 /// ## Examples
28 /// ```no_run
29 /// # use resourcespace_client::Client;
30 /// # async fn example(client: Client) -> Result<(), Box<dyn std::error::Error>> {
31 /// let status = client.system().get_system_status().await?;
32 /// # Ok(())
33 /// # }
34 /// ```
35 pub async fn get_system_status(&self) -> Result<serde_json::Value, RsError> {
36 self.client
37 .send_request("get_system_status", reqwest::Method::GET, ())
38 .await
39 }
40
41 /// Return a summary of daily statistics by activity type.
42 ///
43 /// Note max 365 days as only the current and previous year's data is accessed.
44 ///
45 /// ## Arguments
46 /// * `request` - Parameters built via [`GetDailyStatSummaryRequest`]
47 ///
48 /// ## Returns
49 ///
50 /// Returns an array of daily statistics.
51 ///
52 /// ## TODO: Errors
53 ///
54 /// ## Examples
55 /// ```no_run
56 /// # use resourcespace_client::{Client, api::system::GetDailyStatSummaryRequest};
57 /// # async fn example(client: Client) -> Result<(), Box<dyn std::error::Error>> {
58 /// // Default — last 30 days
59 /// let stats = client.system()
60 /// .get_daily_stat_summary(GetDailyStatSummaryRequest::new())
61 /// .await?;
62 ///
63 /// // Last 7 days
64 /// let stats = client.system()
65 /// .get_daily_stat_summary(GetDailyStatSummaryRequest::new().days(7))
66 /// .await?;
67 /// # Ok(())
68 /// # }
69 /// ```
70 pub async fn get_daily_stat_summary(
71 &self,
72 request: GetDailyStatSummaryRequest,
73 ) -> Result<serde_json::Value, RsError> {
74 request
75 .validate()
76 .map_err(|e| RsError::Validation(e.to_string()))?;
77 self.client
78 .send_request("get_daily_stat_summary", reqwest::Method::GET, request)
79 .await
80 }
81
82 pub async fn get_reports(&self) -> Result<serde_json::Value, RsError> {
83 todo!("available from RS v11.0")
84 }
85
86 pub async fn do_report(&self) -> Result<serde_json::Value, RsError> {
87 todo!("available from RS v11.0")
88 }
89}
90
91#[skip_serializing_none]
92#[derive(Clone, Debug, Default, PartialEq, Serialize, Validate)]
93pub struct GetDailyStatSummaryRequest {
94 /// Number of past days to include in the summary (1–365). Defaults to 30 when omitted.
95 #[validate(range(min = 1, max = 365))]
96 pub days: Option<u16>,
97}
98
99impl GetDailyStatSummaryRequest {
100 pub fn new() -> Self {
101 Self::default()
102 }
103
104 pub fn days(mut self, days: u16) -> Self {
105 self.days = Some(days);
106 self
107 }
108}