paperless/
tag.rs

1use hex_color::HexColor;
2use reqwest::Url;
3use serde::Deserialize;
4
5#[derive(Debug, Deserialize, Copy, Clone)]
6pub struct Id(u64);
7
8impl From<u64> for Id {
9    fn from(value: u64) -> Self {
10        Self(value)
11    }
12}
13impl From<Id> for u64 {
14    fn from(value: Id) -> Self {
15        value.0
16    }
17}
18impl ToString for Id {
19    fn to_string(&self) -> String {
20        self.0.to_string()
21    }
22}
23
24#[derive(Debug, Deserialize)]
25pub struct Tag {
26    pub id: Id,
27    pub slug: String,
28    pub name: String,
29    pub color: HexColor,
30    pub text_color: HexColor,
31    #[serde(rename = "match")]
32    pub match_: String,
33    pub matching_algorithm: u64,
34    pub is_insensitive: bool,
35    pub is_inbox_tag: 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}