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    /// Points are always positioned relative to the drawing position. The first point is always at (0,0).
79    pub points: Vec<Vec<i32>>,
80    pub color: String,
81    pub fill_pattern: FillPatternType,
82    pub stroke_width: i32,
83}
84
85#[typeshare]
86#[derive(Debug, Clone, Deserialize, ToSchema, Serialize)]
87#[serde(rename_all = "camelCase")]
88pub struct PolygonProperties {
89    /// Points are always positioned relative to the drawing position. The first point is always at (0,0).
90    pub points: Vec<Vec<i32>>,
91    pub color: String,
92    pub fill_pattern: FillPatternType,
93    pub stroke_width: i32,
94}
95
96#[typeshare]
97#[derive(Debug, Clone, Deserialize, ToSchema, Serialize)]
98#[serde(rename_all = "camelCase")]
99pub struct LabelTextProperties {
100    pub text: String,
101    pub width: i32,
102    pub height: i32,
103    pub color: String,
104}
105
106#[typeshare]
107#[derive(Debug, Clone, Deserialize, ToSchema, Serialize)]
108#[serde(rename_all = "camelCase")]
109pub struct ImageProperties {
110    pub path: String,
111}
112
113/// Represents user drawing.
114#[typeshare]
115#[derive(Debug, Clone, Deserialize, ToSchema, Serialize)]
116#[serde(tag = "type", content = "properties")]
117pub enum DrawingVariant {
118    Rectangle(RectangleProperties),
119    Ellipse(EllipseProperties),
120    FreeLine(FreeLineProperties),
121    BezierPolygon(PolygonProperties),
122    LabelText(LabelTextProperties),
123    Image(ImageProperties),
124}
125
126/// Used to change the `add_date` of a drawing.
127#[typeshare]
128#[derive(Debug, Clone, Copy, Serialize, Deserialize, ToSchema)]
129#[serde(rename_all = "camelCase")]
130pub struct UpdateAddDateDrawingDto {
131    /// The id of the drawing.
132    pub id: Uuid,
133    /// The date the drawing was added to the map.
134    /// If None, the drawing always existed.
135    pub add_date: Option<NaiveDate>,
136}
137
138/// Used to change the `remove_date` of a drawing.
139#[typeshare]
140#[derive(Debug, Clone, Copy, Serialize, Deserialize, ToSchema)]
141#[serde(rename_all = "camelCase")]
142pub struct UpdateRemoveDateDrawingDto {
143    /// The id of the drawing.
144    pub id: Uuid,
145    /// The date the drawing was removed from the map.
146    /// If None, the drawing is still on the map.
147    pub remove_date: Option<NaiveDate>,
148}
149
150/// Used to change the `notes` of a drawing.
151#[typeshare]
152#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
153#[serde(rename_all = "camelCase")]
154pub struct UpdateNotesDrawingDto {
155    /// The id of the drawing.
156    pub id: Uuid,
157    /// The new Markdown note.
158    pub notes: String,
159}
160
161/// Used to differentiate between different update operations on drawings.
162///
163/// Ordering of enum variants is important.
164/// Serde will try to deserialize starting from the top.
165#[typeshare]
166#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
167#[serde(tag = "type", content = "content")]
168pub enum UpdateDrawingsDto {
169    /// Update the actual drawings data.
170    Update(Vec<DrawingDto>),
171    /// Change the `add_date` of a drawing.
172    UpdateAddDate(Vec<UpdateAddDateDrawingDto>),
173    /// Change the `remove_date` of drawings.
174    UpdateRemoveDate(Vec<UpdateRemoveDateDrawingDto>),
175    /// Change the `notes` of drawings.
176    UpdateNotes(Vec<UpdateNotesDrawingDto>),
177}