pslink_shared/apirequests/
links.rs

1//! types for link requesting and saving.
2
3use enum_map::{Enum, EnumMap};
4use serde::{Deserialize, Serialize};
5
6use crate::datatypes::{FullLink, Link};
7
8use super::general::{EditMode, Filter, Operation, Ordering};
9
10/// Request a list of users respecting the filter and ordering.
11#[derive(Clone, Deserialize, Serialize, Debug)]
12pub struct LinkRequestForm {
13    pub filter: EnumMap<LinkOverviewColumns, Filter>,
14    pub order: Option<Operation<LinkOverviewColumns, Ordering>>,
15    pub offset: usize,
16    pub amount: usize,
17}
18
19impl Default for LinkRequestForm {
20    fn default() -> Self {
21        Self {
22            filter: EnumMap::default(),
23            order: None,
24            offset: 0,
25            amount: 60,
26        }
27    }
28}
29
30/// The Struct that is responsible for creating and editing links.
31#[derive(Default, Debug, Clone, Serialize, Deserialize)]
32pub struct LinkDelta {
33    pub edit: EditMode,
34    pub id: Option<i64>,
35    pub title: String,
36    pub target: String,
37    pub code: String,
38    pub author: i64,
39    pub created_at: Option<chrono::NaiveDateTime>,
40}
41
42impl From<Link> for LinkDelta {
43    /// Automatically create a `LinkDelta` from a Link.
44    fn from(l: Link) -> Self {
45        Self {
46            edit: EditMode::Edit,
47            id: Some(l.id),
48            title: l.title,
49            target: l.target,
50            code: l.code,
51            author: l.author,
52            created_at: Some(l.created_at),
53        }
54    }
55}
56
57impl From<FullLink> for LinkDelta {
58    /// Automatically create a `LinkDelta` from a `FullLink`.
59    fn from(l: FullLink) -> Self {
60        Self {
61            edit: EditMode::Edit,
62            id: Some(l.link.id),
63            title: l.link.title,
64            target: l.link.target,
65            code: l.link.code,
66            author: l.link.author,
67            created_at: Some(l.link.created_at),
68        }
69    }
70}
71
72/// An enumeration of the filterable columns
73#[derive(Clone, Deserialize, Serialize, Debug, PartialEq, Eq, Hash, Enum)]
74pub enum LinkOverviewColumns {
75    Code,
76    Description,
77    Target,
78    Author,
79    Statistics,
80}
81
82/// A struct to request a qr-code from the server
83#[derive(Clone, Deserialize, Serialize, Debug, PartialEq, Eq)]
84pub struct QrCodeRequest {
85    pub link_id: String,
86    pub format: QrCodeFormat,
87}
88
89/// The response to a qr-request
90#[derive(Clone, Deserialize, Serialize, Debug, PartialEq, Eq)]
91pub struct SvgQrCodeResponse {
92    pub svg: String,
93}
94
95/// Available formats of qr-codes
96#[derive(Clone, Deserialize, Serialize, Debug, PartialEq, Eq)]
97pub enum QrCodeFormat {
98    Svg,
99    Png,
100}