backend/model/dto/
drawings.rs

1use crate::model::r#enum::fill_pattern_type::FillPatternType;
2use chrono::{NaiveDate, NaiveDateTime};
3use serde::{Deserialize, Serialize};
4use typeshare::typeshare;
5use utoipa::ToSchema;
6use uuid::Uuid;
7
8/// Represents user drawing.
9#[typeshare]
10#[derive(Debug, Clone, Deserialize, ToSchema, Serialize)]
11#[serde(rename_all = "camelCase")]
12pub struct DrawingDto {
13    pub id: Uuid,
14
15    pub variant: DrawingVariant,
16
17    pub layer_id: Uuid,
18    pub add_date: Option<NaiveDate>,
19    pub remove_date: Option<NaiveDate>,
20    pub rotation: i32,
21    pub scale_x: i32,
22    pub scale_y: i32,
23    pub x: i32,
24    pub y: i32,
25    pub notes: String,
26    pub created_at: Option<NaiveDateTime>,
27    pub modified_at: Option<NaiveDateTime>,
28    pub created_by: Option<Uuid>,
29    pub modified_by: Option<Uuid>,
30}
31
32/// Represents user drawing.
33#[typeshare]
34#[derive(Debug, Clone, Deserialize, ToSchema, Serialize)]
35#[serde(rename_all = "camelCase")]
36pub struct DrawingCreateDto {
37    pub id: Uuid,
38
39    pub variant: DrawingVariant,
40
41    pub layer_id: Uuid,
42    pub add_date: Option<NaiveDate>,
43    pub remove_date: Option<NaiveDate>,
44    pub rotation: i32,
45    pub scale_x: i32,
46    pub scale_y: i32,
47    pub x: i32,
48    pub y: i32,
49    pub notes: String,
50}
51
52#[typeshare]
53#[derive(Debug, Clone, Deserialize, ToSchema, Serialize)]
54#[serde(rename_all = "camelCase")]
55pub struct RectangleProperties {
56    pub width: i32,
57    pub height: i32,
58    pub color: String,
59    pub fill_pattern: FillPatternType,
60    pub stroke_width: i32,
61}
62
63#[typeshare]
64#[derive(Debug, Clone, Deserialize, ToSchema, Serialize)]
65#[serde(rename_all = "camelCase")]
66pub struct EllipseProperties {
67    pub radius_x: i32,
68    pub radius_y: i32,
69    pub color: String,
70    pub fill_pattern: FillPatternType,
71    pub stroke_width: i32,
72}
73
74#[typeshare]
75#[derive(Debug, Clone, Deserialize, ToSchema, Serialize)]
76#[serde(rename_all = "camelCase")]
77pub struct FreeLineProperties {
78    pub points: Vec<Vec<i32>>,
79    pub color: String,
80    pub fill_pattern: FillPatternType,
81    pub stroke_width: i32,
82}
83
84#[typeshare]
85#[derive(Debug, Clone, Deserialize, ToSchema, Serialize)]
86#[serde(rename_all = "camelCase")]
87pub struct PolygonProperties {
88    pub points: Vec<Vec<i32>>,
89    pub color: String,
90    pub fill_pattern: FillPatternType,
91    pub stroke_width: i32,
92}
93
94#[typeshare]
95#[derive(Debug, Clone, Deserialize, ToSchema, Serialize)]
96#[serde(rename_all = "camelCase")]
97pub struct LabelTextProperties {
98    pub text: String,
99    pub width: i32,
100    pub height: i32,
101    pub color: String,
102}
103
104#[typeshare]
105#[derive(Debug, Clone, Deserialize, ToSchema, Serialize)]
106#[serde(rename_all = "camelCase")]
107pub struct ImageProperties {
108    pub path: String,
109}
110
111/// Represents user drawing.
112#[typeshare]
113#[derive(Debug, Clone, Deserialize, ToSchema, Serialize)]
114#[serde(tag = "type", content = "properties")]
115pub enum DrawingVariant {
116    Rectangle(RectangleProperties),
117    Ellipse(EllipseProperties),
118    FreeLine(FreeLineProperties),
119    BezierPolygon(PolygonProperties),
120    LabelText(LabelTextProperties),
121    Image(ImageProperties),
122}
123
124/// Used to change the `add_date` of a drawing.
125#[typeshare]
126#[derive(Debug, Clone, Copy, Serialize, Deserialize, ToSchema)]
127#[serde(rename_all = "camelCase")]
128pub struct UpdateAddDateDrawingDto {
129    /// The id of the drawing.
130    pub id: Uuid,
131    /// The date the drawing was added to the map.
132    /// If None, the drawing always existed.
133    pub add_date: Option<NaiveDate>,
134}
135
136/// Used to change the `remove_date` of a drawing.
137#[typeshare]
138#[derive(Debug, Clone, Copy, Serialize, Deserialize, ToSchema)]
139#[serde(rename_all = "camelCase")]
140pub struct UpdateRemoveDateDrawingDto {
141    /// The id of the drawing.
142    pub id: Uuid,
143    /// The date the drawing was removed from the map.
144    /// If None, the drawing is still on the map.
145    pub remove_date: Option<NaiveDate>,
146}
147
148/// Used to change the `notes` of a drawing.
149#[typeshare]
150#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
151#[serde(rename_all = "camelCase")]
152pub struct UpdateNotesDrawingDto {
153    /// The id of the drawing.
154    pub id: Uuid,
155    /// The new Markdown note.
156    pub notes: String,
157}
158
159/// Used to differentiate between different update operations on drawings.
160///
161/// Ordering of enum variants is important.
162/// Serde will try to deserialize starting from the top.
163#[typeshare]
164#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
165#[serde(tag = "type", content = "content")]
166pub enum UpdateDrawingsDto {
167    /// Update the actual drawings data.
168    Update(Vec<DrawingDto>),
169    /// Change the `add_date` of a drawing.
170    UpdateAddDate(Vec<UpdateAddDateDrawingDto>),
171    /// Change the `remove_date` of drawings.
172    UpdateRemoveDate(Vec<UpdateRemoveDateDrawingDto>),
173    /// Change the `notes` of drawings.
174    UpdateNotes(Vec<UpdateNotesDrawingDto>),
175}