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    /// Order within the map.
23    pub order_index: i32,
24    /// Set if the layer has been soft-deleted
25    pub marked_deleted: bool,
26}
27
28/// Used to differentiate between different update operations on drawings.
29///
30/// Ordering of enum variants is important.
31/// Serde will try to deserialize starting from the top.
32#[typeshare]
33#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
34#[serde(tag = "type", content = "content")]
35pub enum UpdateLayerDto {
36    /// Rename a layer.
37    Rename(LayerRenameDto),
38    /// Change order or multiple layers on a map.
39    Reorder(Vec<Uuid>),
40    /// Restore a soft-deleted layer.
41    RestoreDrawingLayer(RestoreDrawingLayerDto),
42}
43
44/// Query parameters for searching layers.
45#[typeshare]
46#[derive(Debug, Deserialize, IntoParams)]
47pub struct LayerSearchParameters {
48    /// The parent map.
49    pub map_id: Option<i32>,
50    /// The type of layer.
51    pub type_: Option<LayerType>,
52    /// Whether or not the layer is an alternative.
53    pub is_alternative: Option<bool>,
54    /// Return only non-deleted layers
55    pub only_non_deleted: Option<()>,
56}
57
58/// Query parameters for searching layers.
59#[typeshare]
60#[derive(Debug, Clone, Serialize, Deserialize, IntoParams)]
61pub struct LayerRenameDto {
62    /// The layer id.
63    pub id: Uuid,
64    /// The new name.
65    pub name: String,
66}
67
68/// Used to sotf-delete a layer.
69#[typeshare]
70#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
71#[serde(rename_all = "camelCase")]
72pub struct DeleteLayerDto {
73    /// Id of the layer to delete.
74    pub id: Uuid,
75}
76
77/// Used to restore a deleted drawings layer.
78#[typeshare]
79#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
80#[serde(rename_all = "camelCase")]
81pub struct RestoreDrawingLayerDto {
82    /// Id of the layer to be restored.
83    pub id: Uuid,
84}