backend/model/entity/
plantings.rs

1//! All entities associated with [`Planting`].
2
3use chrono::{NaiveDate, NaiveDateTime};
4use diesel::{AsChangeset, Identifiable, Insertable, Queryable};
5use uuid::Uuid;
6
7use crate::schema::plantings;
8
9/// The `Planting` entity.
10#[derive(Debug, Clone, Identifiable, Queryable)]
11#[diesel(table_name = plantings)]
12pub struct Planting {
13    /// The id of the planting.
14    pub id: Uuid,
15    /// The plant that is planted.
16    pub plant_id: i32,
17    /// The x coordinate of the position on the map.
18    pub x: i32,
19    /// The y coordinate of the position on the map.
20    pub y: i32,
21    /// The size of the planting on the map in x direction.
22    pub size_x: i32,
23    /// The size of the planting on the map in y direction.
24    pub size_y: i32,
25    /// The rotation in degrees (0-360) of the plant on the map.
26    pub rotation: f32,
27    /// The date the planting was added to the map.
28    /// If None, the planting always existed.
29    pub add_date: Option<NaiveDate>,
30    /// The date the planting was removed from the map.
31    /// If None, the planting is still on the map.
32    pub remove_date: Option<NaiveDate>,
33    /// Plantings may be linked with a seed.
34    pub seed_id: Option<i32>,
35    /// Is the planting an area of plantings.
36    pub is_area: bool,
37    /*
38    /// The date the planting was created.
39    //pub create_date: NaiveDate,
40
41    /// The date the planting was 'soft' deleted
42    /// and is still able to be restored.
43    //pub delete_date: Option<NaiveDate>,
44    */
45    /// Notes about the planting in Markdown.
46    pub notes: String,
47
48    /// The datetime the planting was created.
49    pub created_at: NaiveDateTime,
50    /// The datetime the planting was last modified.
51    pub modified_at: NaiveDateTime,
52    /// The uuid of the user that created the planting.
53    pub created_by: Uuid,
54    /// The uuid of the user that last modified the planting.
55    pub modified_by: Uuid,
56    /// The plant layer the plantings is on.
57    pub layer_id: Uuid,
58    /// The height of the planting in cm (z direction).
59    pub height: Option<i32>,
60}
61
62/// The `NewPlanting` entity.
63#[derive(Insertable)]
64#[diesel(table_name = plantings)]
65pub struct NewPlanting {
66    /// The id of the planting (set by the frontend)
67    pub id: Uuid,
68    /// The plant that is planted.
69    pub plant_id: i32,
70    /// The x coordinate of the position on the map.
71    pub x: i32,
72    /// The y coordinate of the position on the map.
73    pub y: i32,
74    /// The size of the planting on the map in x direction.
75    pub size_x: i32,
76    /// The size of the planting on the map in y direction.
77    pub size_y: i32,
78    /// The rotation in degrees (0-360) of the plant on the map.
79    pub rotation: f32,
80    /// The date the planting was added to the map.
81    /// If None, the planting always existed.
82    pub add_date: Option<NaiveDate>,
83    /// The date the planting was removed from the map.
84    /// If None, the planting is still on the map.
85    pub remove_date: Option<NaiveDate>,
86    /// Plantings may be linked with a seed.
87    pub seed_id: Option<i32>,
88    /// Is the planting an area of plants.
89    pub is_area: bool,
90    /// The uuid of the user that created the planting.
91    pub created_by: Uuid,
92    /// The user who last modified the planting.
93    pub modified_by: Uuid,
94    /// The plant layer the plantings is on.
95    pub layer_id: Uuid,
96    /// The height of the planting in cm (z direction).
97    pub height: Option<i32>,
98}
99
100/// The `UpdatePlanting` entity.
101#[derive(Debug, Clone, Default, AsChangeset)]
102#[diesel(table_name = plantings)]
103pub struct UpdatePlanting {
104    /// The id of the planting.
105    /// This is not updated.
106    pub id: Uuid,
107    /// The x coordinate of the position on the map.
108    pub x: Option<i32>,
109    /// The y coordinate of the position on the map.
110    pub y: Option<i32>,
111    /// The size of the planting on the map in x direction.
112    pub size_x: Option<i32>,
113    /// The size of the planting on the map in y direction.
114    pub size_y: Option<i32>,
115    /// The rotation of the plant on the map.
116    pub rotation: Option<f32>,
117    /// The date the planting was added to the map.
118    pub add_date: Option<Option<NaiveDate>>,
119    /// The date the planting was removed from the map.
120    pub remove_date: Option<Option<NaiveDate>>,
121    /// Plantings may be linked with a seed.
122    pub seed_id: Option<i32>,
123    /// Notes about the planting in Markdown.
124    pub notes: Option<String>,
125    /// The height of the planting in cm (z direction).
126    pub height: Option<Option<i32>>,
127}