firefly_iii_rust/response/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use serde::Deserialize;

/// A generic response that wraps the common fields the
/// Firefly III API sends in all endpoints.
/// Usually used with the data types from the endpoints.
#[derive(Debug, Deserialize, Default)]
pub struct Response<T> {
    pub data: T,
}

#[derive(Deserialize, Default)]
pub struct EmptyResponse {}

/// This is the struct with the default fields for a
/// paginated response, this is usuall the listing
/// calls, this is paired with the `Paginated` trait
/// that enables the `client.fetch_all` function to
/// return a vector of all resources.
#[derive(Debug, Deserialize, Default)]
pub struct PaginatedResponse<T> {
    pub data: T,
    pub meta: Meta,
}

#[derive(Debug, Deserialize, Default)]
pub struct Meta {
    #[serde(default)]
    pub pagination: Pagination,
}

#[derive(Debug, Deserialize, Default)]
pub struct Pagination {
    pub total: u64,
    pub count: u64,
    pub per_page: u64,
    pub current_page: u64,
    pub total_pages: u64,
}

/// Enables pagination for the requests that require it
/// this way the page information is encoded in the request
/// struct.
pub trait Paginated {
    fn set_page(&mut self, page: u64);
    fn get_page(&self) -> u64;
    fn max_page(&self) -> u64;
}