firefly_iii_rust/response/
mod.rs

1use serde::Deserialize;
2
3/// A generic response that wraps the common fields the
4/// Firefly III API sends in all endpoints.
5/// Usually used with the data types from the endpoints.
6#[derive(Debug, Deserialize, Default)]
7pub struct Response<T> {
8    pub data: T,
9}
10
11#[derive(Deserialize, Default)]
12pub struct EmptyResponse {}
13
14/// This is the struct with the default fields for a
15/// paginated response, this is usuall the listing
16/// calls, this is paired with the `Paginated` trait
17/// that enables the `client.fetch_all` function to
18/// return a vector of all resources.
19#[derive(Debug, Deserialize, Default)]
20pub struct PaginatedResponse<T> {
21    pub data: T,
22    pub meta: Meta,
23}
24
25#[derive(Debug, Deserialize, Default)]
26pub struct Meta {
27    #[serde(default)]
28    pub pagination: Pagination,
29}
30
31#[derive(Debug, Deserialize, Default)]
32pub struct Pagination {
33    pub total: u64,
34    pub count: u64,
35    pub per_page: u64,
36    pub current_page: u64,
37    pub total_pages: u64,
38}
39
40/// Enables pagination for the requests that require it
41/// this way the page information is encoded in the request
42/// struct.
43pub trait Paginated {
44    fn set_page(&mut self, page: u64);
45    fn get_page(&self) -> u64;
46    fn max_page(&self) -> u64;
47}
48