diff options
Diffstat (limited to 'lib/warden-core/src/pagination/mod.rs')
| -rw-r--r-- | lib/warden-core/src/pagination/mod.rs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/lib/warden-core/src/pagination/mod.rs b/lib/warden-core/src/pagination/mod.rs new file mode 100644 index 0000000..25fb083 --- /dev/null +++ b/lib/warden-core/src/pagination/mod.rs @@ -0,0 +1,58 @@ +use serde::{Deserialize, Serialize}; +use utoipa::ToSchema; + +/// Arguments used for cursor-based pagination. +#[derive(Deserialize, Debug, ToSchema)] +#[serde(rename_all = "camelCase")] +pub struct PaginationArgs { + /// Returns the first `n` items from the list. + pub first: Option<i64>, + + /// A cursor pointing to the position after which items should be returned. + pub after: Option<String>, + + /// Returns the last `n` items from the list. + pub last: Option<i64>, + + /// A cursor pointing to the position before which items should be returned. + pub before: Option<String>, +} + +/// Metadata describing the current page of results. +#[derive(Serialize, Debug, ToSchema)] +#[serde(rename_all = "camelCase")] +pub struct PageInfo { + /// Indicates whether there are more items when paginating forward. + pub has_next_page: bool, + + /// Indicates whether there are more items when paginating backward. + pub has_previous_page: bool, + + /// The cursor corresponding to the first item in the current page. + pub start_cursor: Option<String>, + + /// The cursor corresponding to the last item in the current page. + pub end_cursor: Option<String>, +} + +/// A paginated connection containing edges and pagination metadata. +#[derive(Serialize, Debug, ToSchema)] +#[serde(rename_all = "camelCase")] +pub struct Connection<T> { + /// A list of edges, each containing a node and its cursor. + pub edges: Vec<Edge<T>>, + + /// Information about pagination for this connection. + pub page_info: PageInfo, +} + +/// An edge in a connection, representing a node and its cursor. +#[derive(Serialize, Debug, ToSchema)] +#[serde(rename_all = "camelCase")] +pub struct Edge<T> { + /// The item/node contained in this edge. + pub node: T, + + /// A cursor for this node, used in pagination. + pub cursor: String, +} |
