1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use serde::Deserialize;
use serde::Serialize;
use typeshare::typeshare;
use utoipa::IntoParams;
use utoipa::ToSchema;
use uuid::Uuid;

use crate::model::r#enum::layer_type::LayerType;

/// A Dto that represenets a layer on a map.
#[typeshare]
#[derive(Serialize, Deserialize, ToSchema, Debug, Clone)]
pub struct LayerDto {
    /// The id of the layer.
    pub id: Uuid,
    /// The id of the map this layer belongs to.
    pub map_id: i32,
    /// The type of layer.
    pub type_: LayerType,
    /// The name of the layer.
    pub name: String,
    /// A flag indicating if this layer is an user created alternative.
    pub is_alternative: bool,
    /// Order within the map.
    pub order_index: i32,
    /// Set if the layer has been soft-deleted
    pub marked_deleted: bool,
}

/// Used to differentiate between different update operations on drawings.
///
/// Ordering of enum variants is important.
/// Serde will try to deserialize starting from the top.
#[typeshare]
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
#[serde(tag = "type", content = "content")]
pub enum UpdateLayerDto {
    /// Rename a layer.
    Rename(LayerRenameDto),
    /// Change order or multiple layers on a map.
    Reorder(Vec<Uuid>),
    /// Restore a soft-deleted layer.
    RestoreDrawingLayer(RestoreDrawingLayerDto),
}

/// Query parameters for searching layers.
#[typeshare]
#[derive(Debug, Deserialize, IntoParams)]
pub struct LayerSearchParameters {
    /// The parent map.
    pub map_id: Option<i32>,
    /// The type of layer.
    pub type_: Option<LayerType>,
    /// Whether or not the layer is an alternative.
    pub is_alternative: Option<bool>,
    /// Return only non-deleted layers
    pub only_non_deleted: Option<()>,
}

/// Query parameters for searching layers.
#[typeshare]
#[derive(Debug, Clone, Serialize, Deserialize, IntoParams)]
pub struct LayerRenameDto {
    /// The layer id.
    pub id: Uuid,
    /// The new name.
    pub name: String,
}

/// Used to sotf-delete a layer.
#[typeshare]
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct DeleteLayerDto {
    /// Id of the layer to delete.
    pub id: Uuid,
}

/// Used to restore a deleted drawings layer.
#[typeshare]
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct RestoreDrawingLayerDto {
    /// Id of the layer to be restored.
    pub id: Uuid,
}