backend/model/dto/
plantings.rs

1//! All DTOs associated with [`PlantingDto`].
2
3use chrono::{NaiveDate, NaiveDateTime};
4use serde::{Deserialize, Serialize};
5use typeshare::typeshare;
6use utoipa::{IntoParams, ToSchema};
7use uuid::Uuid;
8
9/// Represents a plant on a map.
10/// E.g. a user selects a plant from the search results and plants it on the map.
11#[typeshare]
12#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
13#[serde(rename_all = "camelCase")]
14pub struct PlantingDto {
15    /// The id of the planting.
16    pub id: Uuid,
17    /// The plant layer the plantings is on.
18    pub layer_id: Uuid,
19    /// The plant that is planted.
20    pub plant_id: i32,
21    /// The actual time the planting was added to the database. This is read-only.
22    pub created_at: Option<NaiveDateTime>,
23    /// When the planting was last modified on the database. This is read-only.
24    pub modified_at: Option<NaiveDateTime>,
25    /// The id of the user who planted the planting. This is read-only.
26    pub created_by: Option<Uuid>,
27    /// The id of the last user who touched the planting. This is read-only.
28    pub modified_by: Option<Uuid>,
29    /// The x coordinate of the position on the map.
30    pub x: i32,
31    /// The y coordinate of the position on the map.
32    pub y: i32,
33    /// The size of the planting on the map in x direction.
34    pub size_x: i32,
35    /// The size of the planting on the map in y direction.
36    pub size_y: i32,
37    /// The height of the planting in cm (z direction).
38    pub height: Option<i32>,
39    /// The rotation in degrees (0-360) of the plant on the map.
40    pub rotation: f32,
41    /// The date the planting was added to the map.
42    /// If None, the planting always existed.
43    pub add_date: Option<NaiveDate>,
44    /// The date the planting was removed from the map.
45    /// If None, the planting is still on the map.
46    pub remove_date: Option<NaiveDate>,
47    /// Plantings may be linked with a seed.
48    pub seed_id: Option<i32>,
49    /// Equivalent to the seed name.
50    /// It is used to display the full plant name on a map
51    /// even if a user does not have access to the seed.
52    pub additional_name: Option<String>,
53    /// Is the planting an area of plantings.
54    pub is_area: bool,
55    /// Notes about the planting in Markdown.
56    pub notes: String,
57}
58
59/// Used to differentiate between different update operations on plantings.
60///
61/// Ordering of enum variants is important.
62/// Serde will try to deserialize starting from the top.
63#[typeshare]
64#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
65#[serde(tag = "type", content = "content")]
66pub enum UpdatePlantingDto {
67    /// Transform a planting.
68    Transform(Vec<TransformPlantingDto>),
69    /// Move a planting on the map.
70    Move(Vec<MovePlantingDto>),
71    /// Change the `add_date` of a planting.
72    UpdateAddDate(Vec<UpdateAddDatePlantingDto>),
73    /// Change the `remove_date` of a planting.
74    UpdateRemoveDate(Vec<UpdateRemoveDatePlantingDto>),
75    /// Update Markdown notes.
76    UpdateNote(Vec<UpdatePlantingNoteDto>),
77}
78
79/// Used to transform an existing planting.
80#[typeshare]
81#[derive(Debug, Clone, Copy, Serialize, Deserialize, ToSchema)]
82#[serde(rename_all = "camelCase")]
83pub struct TransformPlantingDto {
84    /// The id of the planting.
85    pub id: Uuid,
86    /// The x coordinate of the position on the map.
87    pub x: i32,
88    /// The y coordinate of the position on the map.
89    pub y: i32,
90    /// The rotation of the plant on the map.
91    pub rotation: f32,
92    /// The x scale of the plant on the map.
93    pub size_x: i32,
94    /// The y scale of the plant on the map.
95    pub size_y: i32,
96    /// The height of the plant.
97    pub height: Option<i32>,
98}
99
100/// Used to move an existing planting.
101#[typeshare]
102#[derive(Debug, Clone, Copy, Serialize, Deserialize, ToSchema)]
103#[serde(rename_all = "camelCase")]
104pub struct MovePlantingDto {
105    /// The id of the planting.
106    pub id: Uuid,
107    /// The x coordinate of the position on the map.
108    pub x: i32,
109    /// The y coordinate of the position on the map.
110    pub y: i32,
111}
112
113/// Used to change the `add_date` of a planting.
114#[typeshare]
115#[derive(Debug, Clone, Copy, Serialize, Deserialize, ToSchema)]
116#[serde(rename_all = "camelCase")]
117pub struct UpdateAddDatePlantingDto {
118    /// The id of the planting.
119    pub id: Uuid,
120    /// The date the planting was added to the map.
121    /// If None, the planting always existed.
122    pub add_date: Option<NaiveDate>,
123}
124
125/// Used to change the `remove_date` of a planting.
126#[typeshare]
127#[derive(Debug, Clone, Copy, Serialize, Deserialize, ToSchema)]
128#[serde(rename_all = "camelCase")]
129pub struct UpdateRemoveDatePlantingDto {
130    /// The id of the planting.
131    pub id: Uuid,
132    /// The date the planting was removed from the map.
133    /// If None, the planting is still on the map.
134    pub remove_date: Option<NaiveDate>,
135}
136
137/// Update Markdown planting notes.
138#[typeshare]
139#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
140#[serde(rename_all = "camelCase")]
141pub struct UpdatePlantingNoteDto {
142    /// The id of the planting.
143    pub id: Uuid,
144    /// Notes about the planting in Markdown.
145    pub notes: String,
146}
147
148/// Used to delete a planting.
149#[typeshare]
150#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
151#[serde(rename_all = "camelCase")]
152pub struct DeletePlantingDto {
153    /// Id of the planting to delete.
154    pub id: Uuid,
155}
156
157/// Query parameters for searching plantings.
158#[typeshare]
159#[derive(Debug, Deserialize, IntoParams)]
160pub struct PlantingSearchParameters {
161    /// The id of the plant the planting references.
162    pub plant_id: Option<i32>,
163    /// The id of the plants layer the planting is placed on.
164    pub layer_id: Option<Uuid>,
165    /// Plantings that exist around this date are returned.
166    pub relative_to_date: NaiveDate,
167}