paperless/
document_type.rs

1//! # Document type
2//!
3//! A document type is a category of document, like invoice, receipt, bank statement, ...
4
5use reqwest::Url;
6use serde::Deserialize;
7
8#[derive(Debug, Deserialize, Copy, Clone)]
9pub struct Id(u64);
10
11impl From<u64> for Id {
12    fn from(value: u64) -> Self {
13        Self(value)
14    }
15}
16impl From<Id> for u64 {
17    fn from(value: Id) -> Self {
18        value.0
19    }
20}
21impl ToString for Id {
22    fn to_string(&self) -> String {
23        self.0.to_string()
24    }
25}
26
27#[derive(Debug, Deserialize)]
28pub struct DocumentType {
29    pub id: Id,
30    pub slug: String,
31    pub name: String,
32    #[serde(rename = "match")]
33    pub match_: String,
34    pub matching_algorithm: u64,
35    pub is_insensitive: bool,
36    pub document_count: u64,
37}
38
39#[derive(Debug, Default)]
40pub struct Filter {
41    name_starts_with: Option<String>,
42    name_ends_with: Option<String>,
43    name_contains: Option<String>,
44    name_is: Option<String>,
45}
46
47impl Filter {
48    pub fn insert_query(self, url: &mut Url) {
49        url.query_pairs_mut()
50            .append_pair(
51                "name__istartswith",
52                &self.name_starts_with.unwrap_or_default(),
53            )
54            .append_pair("name__iendswith", &self.name_ends_with.unwrap_or_default())
55            .append_pair("name__icontains", &self.name_contains.unwrap_or_default())
56            .append_pair("name__iexact", &self.name_is.unwrap_or_default());
57    }
58}