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 (planning time).
28 /// If None, the planting always existed.
29 pub add_date: Option<NaiveDate>,
30 /// The date the planting was removed from the map (planning time).
31 /// If None, the planting was never removed.
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 /*
39 /// The date the planting was 'soft' deleted
40 /// and is still able to be restored (not yet implemented).
41 // pub deleted_at : Option<NaiveDate>,
42 */
43 /// Notes about the planting in Markdown.
44 pub notes: String,
45
46 /// The datetime the planting was created (clock time)
47 pub created_at: NaiveDateTime,
48 /// The datetime the planting was last modified (clock time).
49 pub modified_at: NaiveDateTime,
50 /// The uuid of the user that created the planting.
51 pub created_by: Uuid,
52 /// The uuid of the user that last modified the planting.
53 pub modified_by: Uuid,
54 /// The plant layer the plantings is on.
55 pub layer_id: Uuid,
56 /// The height of the planting in cm (z direction).
57 pub height: Option<i32>,
58}
59
60/// The `NewPlanting` entity.
61#[derive(Insertable)]
62#[diesel(table_name = plantings)]
63pub struct NewPlanting {
64 /// The id of the planting (set by the frontend)
65 pub id: Uuid,
66 /// The plant that is planted.
67 pub plant_id: i32,
68 /// The x coordinate of the position on the map.
69 pub x: i32,
70 /// The y coordinate of the position on the map.
71 pub y: i32,
72 /// The size of the planting on the map in x direction.
73 pub size_x: i32,
74 /// The size of the planting on the map in y direction.
75 pub size_y: i32,
76 /// The rotation in degrees (0-360) of the plant on the map.
77 pub rotation: f32,
78 /// The date the planting was added to the map.
79 /// If None, the planting always existed.
80 pub add_date: Option<NaiveDate>,
81 /// The date the planting was removed from the map.
82 /// If None, the planting is still on the map.
83 pub remove_date: Option<NaiveDate>,
84 /// Plantings may be linked with a seed.
85 pub seed_id: Option<i32>,
86 /// Is the planting an area of plants.
87 pub is_area: bool,
88 /// The uuid of the user that created the planting.
89 pub created_by: Uuid,
90 /// The user who last modified the planting.
91 pub modified_by: Uuid,
92 /// The plant layer the plantings is on.
93 pub layer_id: Uuid,
94 /// The height of the planting in cm (z direction).
95 pub height: Option<i32>,
96}
97
98/// The `UpdatePlanting` entity.
99#[derive(Debug, Clone, Default, AsChangeset)]
100#[diesel(table_name = plantings)]
101pub struct UpdatePlanting {
102 /// The id of the planting.
103 /// This is not updated.
104 pub id: Uuid,
105 /// The x coordinate of the position on the map.
106 pub x: Option<i32>,
107 /// The y coordinate of the position on the map.
108 pub y: Option<i32>,
109 /// The size of the planting on the map in x direction.
110 pub size_x: Option<i32>,
111 /// The size of the planting on the map in y direction.
112 pub size_y: Option<i32>,
113 /// The rotation of the plant on the map.
114 pub rotation: Option<f32>,
115 /// The date the planting was added to the map.
116 pub add_date: Option<Option<NaiveDate>>,
117 /// The date the planting was removed from the map.
118 pub remove_date: Option<Option<NaiveDate>>,
119 /// Plantings may be linked with a seed.
120 pub seed_id: Option<i32>,
121 /// Notes about the planting in Markdown.
122 pub notes: Option<String>,
123 /// The height of the planting in cm (z direction).
124 pub height: Option<Option<i32>>,
125}