backend/model/dto/
drawings.rs

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