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: i64,
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: i32,
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<i64>,
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: i64,
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: i32,
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<i64>,
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 /// Notes about the planting in Markdown.
97 pub notes: String,
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<i32>,
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<i64>,
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}