Skip to main content

uptrakit_openapi_client/
update_history.rs

1use crate::Result;
2use crate::UptrakitClient;
3use crate::types_impl::pagination::PaginatedResponse;
4use crate::types_impl::update_history::{UpdateHistoryQuery, UpdateHistoryResponse};
5use uuid::Uuid;
6
7impl UptrakitClient {
8    /// List update history with optional filters and pagination.
9    pub async fn list_update_history(
10        &self,
11        query: &UpdateHistoryQuery,
12    ) -> Result<PaginatedResponse<UpdateHistoryResponse>> {
13        self.get_with_query(crate::paths::update_history::BASE, query)
14            .await
15    }
16
17    /// Fetch all update history entries matching the given filters across all pages.
18    ///
19    /// Automatically iterates through every page at [`MAX_PER_PAGE`] items per
20    /// request. The `page` and `per_page` fields of `query` are ignored; use
21    /// [`list_update_history`] for manual pagination control.
22    ///
23    /// [`MAX_PER_PAGE`]: uptrakit_web_api_types::pagination::MAX_PER_PAGE
24    /// [`list_update_history`]: Self::list_update_history
25    pub async fn list_all_update_history(
26        &self,
27        query: &UpdateHistoryQuery,
28    ) -> Result<Vec<UpdateHistoryResponse>> {
29        self.fetch_all_pages(crate::paths::update_history::BASE, query)
30            .await
31    }
32
33    /// Get a single update history entry by ID.
34    pub async fn get_update_history(&self, id: &Uuid) -> Result<UpdateHistoryResponse> {
35        self.get(&crate::paths::update_history::by_id(id)).await
36    }
37}
38
39#[cfg(test)]
40mod tests {
41    use crate::types_impl::update_history::{UpdateHistoryQuery, UpdateStatus};
42    use uuid::Uuid;
43
44    #[test]
45    fn update_history_query_serialization_with_filters() {
46        let host_id = Uuid::parse_str("11111111-1111-1111-1111-111111111111").expect("valid uuid");
47        let query = UpdateHistoryQuery::new(
48            Some(host_id),
49            None,
50            Some(UpdateStatus::Completed),
51            Some(2),
52            Some(10),
53        );
54        let qs = serde_urlencoded::to_string(&query).expect("serialize");
55        assert!(qs.contains("host_id=11111111-1111-1111-1111-111111111111"));
56        assert!(qs.contains("status=completed"));
57        assert!(qs.contains("page=2"));
58        assert!(qs.contains("per_page=10"));
59    }
60
61    #[test]
62    fn update_history_query_serialization_skips_none() {
63        let query = UpdateHistoryQuery::new(None, None, None, None, None);
64        let qs = serde_urlencoded::to_string(&query).expect("serialize");
65        assert!(qs.is_empty());
66    }
67}