backend/model/dto/
drawings.rs

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