Skip to main content

paperless_api/metadata/
custom_field.rs

1//! Types related to custom fields.
2
3use serde::{Deserialize, Serialize};
4
5use paperless_api_macros::{CreateDto, Item, UpdateDto};
6
7use crate::id::{CustomFieldId, SelectableOptionId};
8
9/// Custom field definition.
10#[derive(Debug, Clone, Deserialize, Serialize, CreateDto, UpdateDto, Item)]
11pub struct CustomField {
12    /// Unique identifier of the custom field.
13    #[dto(skip)]
14    pub id: CustomFieldId,
15
16    /// Name of the custom field.
17    pub name: String,
18
19    /// Data type of the custom field.
20    pub data_type: CustomFieldDataType,
21
22    /// Extra data for the custom field, such as currency or select options.
23    pub extra_data: Option<CustomFieldExtraData>,
24
25    /// Number of documents that have this custom field set.
26    #[dto(skip)]
27    #[serde(default)]
28    pub document_count: u32,
29}
30
31/// Custom field value of an existing document.
32#[derive(Debug, Clone, Deserialize, Serialize)]
33pub struct DocumentCustomField {
34    /// Unique identifier of the custom field.
35    pub field: CustomFieldId,
36
37    /// Value of the custom field.
38    pub value: String,
39}
40
41/// Extra data for a custom field.
42#[derive(Debug, Clone, Deserialize, Serialize)]
43pub struct CustomFieldExtraData {
44    /// Default currency for monetary fields.
45    pub default_currency: Option<String>,
46
47    /// Selectable options for select fields.
48    pub select_options: Option<Vec<SelectableOption>>,
49}
50
51/// A selectable option for a custom field.
52#[derive(Debug, Clone, Deserialize, Serialize)]
53pub struct SelectableOption {
54    /// Unique identifier of the option.
55    pub id: SelectableOptionId,
56
57    /// Label of the option.
58    pub label: String,
59}
60
61/// Data type of a custom field.
62#[derive(Debug, Default, Clone, Deserialize, Serialize)]
63#[serde(rename_all = "lowercase")]
64pub enum CustomFieldDataType {
65    #[default]
66    String,
67    Url,
68    Date,
69    Boolean,
70    Integer,
71    Float,
72    Monetary,
73    Documentlink,
74    Select,
75    Longtext,
76}