Skip to main content

hatchet_sdk/clients/rest/features/
pagination.rs

1use std::collections::HashMap;
2
3use crate::clients::rest::models::V1TaskEventList200ResponsePagination;
4
5/// Converts an auto-generated `Option<HashMap<String, Value>>` to a flat `Value::Object`,
6/// defaulting to `{}`. Used by feature client `From` impls.
7pub(super) fn hash_map_to_value(
8    value: Option<HashMap<String, serde_json::Value>>,
9) -> serde_json::Value {
10    value
11        .and_then(|map| serde_json::to_value(map).ok())
12        .unwrap_or_else(|| serde_json::json!({}))
13}
14
15/// Pagination metadata returned by list endpoints.
16#[derive(Clone, Debug)]
17pub struct PaginationResponse {
18    pub current_page: Option<i64>,
19    pub num_pages: Option<i64>,
20    pub next_page: Option<i64>,
21}
22
23impl From<Box<V1TaskEventList200ResponsePagination>> for PaginationResponse {
24    fn from(response: Box<V1TaskEventList200ResponsePagination>) -> Self {
25        Self {
26            current_page: response.current_page,
27            num_pages: response.num_pages,
28            next_page: response.next_page,
29        }
30    }
31}