backend/model/dto/
layers.rs

1use serde::Deserialize;
2use serde::Serialize;
3use typeshare::typeshare;
4use utoipa::IntoParams;
5use utoipa::ToSchema;
6use uuid::Uuid;
7
8use crate::model::r#enum::layer_type::LayerType;
9
10/// A Dto that represents a layer on a map.
11#[typeshare]
12#[derive(Serialize, Deserialize, ToSchema, Debug, Clone)]
13pub struct LayerDto {
14    /// The id of the layer.
15    pub id: Uuid,
16    /// The type of layer.
17    pub type_: LayerType,
18    /// The id of the map this layer belongs to.
19    pub map_id: i32,
20    /// The name of the layer.
21    pub name: String,
22    /// A flag indicating if this layer is an user created alternative.
23    pub is_alternative: bool,
24    /// Order within the map.
25    pub order_index: i32,
26    /// Set if the layer has been soft-deleted
27    pub marked_deleted: bool,
28}
29
30/// Used to differentiate between different update operations on drawings.
31///
32/// Ordering of enum variants is important.
33/// Serde will try to deserialize starting from the top.
34#[typeshare]
35#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
36#[serde(tag = "type", content = "content")]
37pub enum UpdateLayerDto {
38    /// Rename a layer.
39    Rename(LayerRenameDto),
40    /// Change order or multiple layers on a map.
41    Reorder(Vec<Uuid>),
42    /// Restore a soft-deleted layer.
43    RestoreDrawingLayer(RestoreDrawingLayerDto),
44}
45
46/// Query parameters for searching layers.
47#[typeshare]
48#[derive(Debug, Deserialize, IntoParams)]
49pub struct LayerSearchParameters {
50    /// The parent map.
51    pub map_id: Option<i32>,
52    /// The type of layer.
53    pub type_: Option<LayerType>,
54    /// Whether or not the layer is an alternative.
55    pub is_alternative: Option<bool>,
56    /// Return only non-deleted layers
57    pub only_non_deleted: Option<()>,
58}
59
60/// Query parameters for searching layers.
61#[typeshare]
62#[derive(Debug, Clone, Serialize, Deserialize, IntoParams)]
63pub struct LayerRenameDto {
64    /// The layer id.
65    pub id: Uuid,
66    /// The new name.
67    pub name: String,
68}
69
70/// Used to sotf-delete a layer.
71#[typeshare]
72#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
73#[serde(rename_all = "camelCase")]
74pub struct DeleteLayerDto {
75    /// Id of the layer to delete.
76    pub id: Uuid,
77}
78
79/// Used to restore a deleted drawings layer.
80#[typeshare]
81#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
82#[serde(rename_all = "camelCase")]
83pub struct RestoreDrawingLayerDto {
84    /// Id of the layer to be restored.
85    pub id: Uuid,
86}