Skip to main content

paperless_api/
dto.rs

1//! DTO traits and helpers.
2
3use serde::Serialize;
4
5use crate::id::PaperlessId;
6
7/// Marker trait for DTOs used to create new items.
8pub trait CreateDto: Serialize {
9    /// The ID type for this item.
10    type Id: PaperlessId;
11
12    /// The base type for the DTO.
13    type BaseType: serde::de::DeserializeOwned;
14
15    /// Returns the API endpoint for this item.
16    fn endpoint() -> &'static str;
17}
18
19/// Marker trait for DTOs used to update existing items.
20pub trait UpdateDto: Serialize {
21    /// The ID type for this item.
22    type Id: PaperlessId;
23
24    /// The base type for the DTO.
25    type BaseType: serde::de::DeserializeOwned;
26
27    /// Returns the API endpoint for this item.
28    fn endpoint() -> &'static str;
29}
30
31/// Trait for items that can be managed via the Paperless API.
32pub trait Item {
33    /// The ID type for this item.
34    type Id: PaperlessId;
35
36    /// The base type for the DTO.
37    type BaseType: serde::de::DeserializeOwned;
38
39    /// Returns the API endpoint for this item.
40    fn endpoint() -> &'static str;
41
42    /// Returns the ID of this item.
43    fn id(&self) -> Self::Id;
44}