akahu_client/models/mod.rs
1//! Akahu API data models and response types.
2
3mod account;
4mod identity;
5mod me;
6mod transaction;
7
8pub use account::*;
9pub use identity::*;
10pub use me::*;
11pub use transaction::*;
12
13use serde::{Deserialize, Serialize};
14
15use crate::Cursor;
16
17// TODO: could we combine all three of these response types into one generic type?
18
19/// Standard error response structure from Akahu API
20///
21/// All API errors follow this format with a success flag and message field.
22#[derive(Debug, Deserialize)]
23pub struct ErrorResponse {
24 /// Always false for error responses
25 pub success: bool,
26 /// Error message from the API
27 pub message: String,
28}
29
30/// Standard API response wrapper for a single item.
31///
32/// Most Akahu API endpoints that return a single resource wrap the response
33/// in this format with a `success` field and the actual data in the `item` field.
34///
35/// # Example JSON
36/// ```json
37/// {
38/// "success": true,
39/// "item": { ... }
40/// }
41/// ```
42///
43/// [<https://developers.akahu.nz/docs/response-formatting>]
44#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
45pub struct ItemResponse<T> {
46 /// Indicates if the request was successful.
47 pub success: bool,
48
49 /// The resource data.
50 pub item: T,
51}
52
53/// Standard API response wrapper for a list of items.
54///
55/// Most Akahu API endpoints that return a list of resources wrap the response
56/// in this format with a `success` field and the actual data in the `items` array.
57///
58/// # Example JSON
59/// ```json
60/// {
61/// "success": true,
62/// "items": [...]
63/// }
64/// ```
65///
66/// [<https://developers.akahu.nz/docs/response-formatting>]
67#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
68pub struct ListResponse<T> {
69 /// Indicates if the request was successful.
70 pub success: bool,
71
72 /// The list of resources.
73 pub items: Vec<T>,
74}
75
76/// Standard API response wrapper for paginated items.
77///
78/// Used by endpoints that support cursor-based pagination, such as transaction listings.
79/// The cursor object contains a `next` field that can be used to fetch the next page.
80///
81/// # Example JSON
82/// ```json
83/// {
84/// "success": true,
85/// "items": [...],
86/// "cursor": {
87/// "next": "cursor_token..."
88/// }
89/// }
90/// ```
91///
92/// [<https://developers.akahu.nz/docs/response-formatting>]
93#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
94pub struct PaginatedResponse<T> {
95 /// Indicates if the request was successful.
96 pub success: bool,
97
98 /// The list of resources for this page.
99 pub items: Vec<T>,
100
101 /// Cursor information for pagination.
102 pub cursor: CursorObject,
103}
104
105/// Cursor for paginating through transaction results.
106#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
107pub struct CursorObject {
108 /// Cursor value to use for fetching the next page of results.
109 pub next: Option<Cursor>,
110}