Skip to main content

asana_cli/api/
pagination.rs

1//! Pagination helpers matching Asana's REST API structure.
2
3use serde::Deserialize;
4
5/// Metadata describing the next page of a list response.
6#[derive(Debug, Clone, Deserialize)]
7pub struct PaginationInfo {
8    /// Offset token for subsequent calls.
9    pub offset: Option<String>,
10    /// Canonical path for the next page.
11    pub path: Option<String>,
12    /// Canonical URI when provided.
13    pub uri: Option<String>,
14}
15
16impl PaginationInfo {
17    /// Return the offset token if present.
18    #[must_use]
19    pub fn offset(&self) -> Option<&str> {
20        self.offset.as_deref()
21    }
22}
23
24/// Generic Asana list response where data is wrapped with pagination metadata.
25#[derive(Debug, Clone, Deserialize)]
26pub struct ListResponse<T> {
27    /// Data payload.
28    pub data: Vec<T>,
29    /// Pagination metadata, when more items are available.
30    #[serde(default)]
31    pub next_page: Option<PaginationInfo>,
32}
33
34impl<T> ListResponse<T> {
35    /// Determine whether a subsequent request is required.
36    #[must_use]
37    pub fn has_more(&self) -> bool {
38        self.next_page
39            .as_ref()
40            .and_then(PaginationInfo::offset)
41            .is_some()
42    }
43}