backend/model/entity/
areas.rs

1//! All area entities: `Shading`, `Hydrology` and `SoilTexture`
2
3use chrono::{NaiveDate, NaiveDateTime};
4use diesel::{AsChangeset, Identifiable, Insertable, Queryable};
5use postgis_diesel::types::{Point, Polygon};
6use uuid::Uuid;
7
8use crate::{
9    model::r#enum::{
10        shade::Shade, soil_texture::SoilTextureEnum, water_requirement::WaterRequirementEnum,
11    },
12    schema::{hydrologies, shadings, soil_textures},
13};
14
15/// The `Shading` entity.
16#[derive(Debug, Clone, Identifiable, Queryable, Insertable)]
17#[diesel(table_name = shadings)]
18pub struct Shading {
19    /// The id of the shading.
20    pub id: Uuid,
21    /// The plant layer the shadings is on.
22    pub layer_id: Uuid,
23    /// The type/strength of shade.
24    pub shade: Shade,
25    /// The position of the shade on the map.
26    pub geometry: Polygon<Point>,
27    /// The date the shading was added to the map.
28    /// If None, the shading always existed.
29    pub add_date: Option<NaiveDate>,
30    /// The date the shading was removed from the map.
31    /// If None, the shading is still on the map.
32    pub remove_date: Option<NaiveDate>,
33    /// Markdown notes
34    pub notes: String,
35    /// The date the Shading was created.
36    pub created_at: NaiveDateTime,
37    /// The date the Shading was modified.
38    pub modified_at: NaiveDateTime,
39    /// The ID of the user who created the Shading.
40    pub created_by: Uuid,
41    /// The ID of the user who last modified the Shading.
42    pub modified_by: Uuid,
43}
44
45/// The `UpdateShading` entity.
46#[derive(Debug, Clone, Default, AsChangeset)]
47#[diesel(table_name = shadings)]
48pub struct UpdateShading {
49    pub id: Uuid,
50    pub shade: Option<Shade>,
51    pub geometry: Option<Polygon<Point>>,
52    pub add_date: Option<Option<NaiveDate>>,
53    pub remove_date: Option<Option<NaiveDate>>,
54    pub notes: Option<String>,
55    pub modified_by: Uuid,
56}
57
58/// The `Hydrology` entity.
59#[derive(Debug, Clone, Identifiable, Queryable, Insertable)]
60#[diesel(table_name = hydrologies)]
61pub struct Hydrology {
62    /// The id of the hydrology.
63    pub id: Uuid,
64    /// The plant layer the hydrology is on.
65    pub layer_id: Uuid,
66    /// The water requirement.
67    pub water_requirement: WaterRequirementEnum,
68    /// The position of the hydrology on the map.
69    pub geometry: Polygon<Point>,
70    /// The date the hydrology was added to the map.
71    /// If None, the hydrology always existed.
72    pub add_date: Option<NaiveDate>,
73    /// The date the hydrology was removed from the map.
74    /// If None, the hydrology is still on the map.
75    pub remove_date: Option<NaiveDate>,
76    /// Markdown notes
77    pub notes: String,
78    /// The date the Shading was created.
79    pub created_at: NaiveDateTime,
80    /// The date the Shading was modified.
81    pub modified_at: NaiveDateTime,
82    /// The ID of the user who created the Shading.
83    pub created_by: Uuid,
84    /// The ID of the user who last modified the Shading.
85    pub modified_by: Uuid,
86}
87
88/// The `UpdateHydrology` entity.
89#[derive(Debug, Clone, Default, AsChangeset)]
90#[diesel(table_name = hydrologies)]
91pub struct UpdateHydrology {
92    pub id: Uuid,
93    pub water_requirement: Option<WaterRequirementEnum>,
94    pub geometry: Option<Polygon<Point>>,
95    pub add_date: Option<Option<NaiveDate>>,
96    pub remove_date: Option<Option<NaiveDate>>,
97    pub notes: Option<String>,
98    pub modified_by: Uuid,
99}
100
101/// The `SoilTexture` entity.
102#[derive(Debug, Clone, Identifiable, Queryable, Insertable)]
103#[diesel(table_name = soil_textures)]
104pub struct SoilTexture {
105    /// The id of the shading.
106    pub id: Uuid,
107    /// The plant layer the shadings is on.
108    pub layer_id: Uuid,
109    /// The kind of soil texture.
110    pub soil_texture: SoilTextureEnum,
111    /// The position of the shade on the map.
112    pub geometry: Polygon<Point>,
113    /// The date the shading was added to the map.
114    /// If None, the shading always existed.
115    pub add_date: Option<NaiveDate>,
116    /// The date the shading was removed from the map.
117    /// If None, the shading is still on the map.
118    pub remove_date: Option<NaiveDate>,
119    /// Markdown notes
120    pub notes: String,
121    /// The date the Shading was created.
122    pub created_at: NaiveDateTime,
123    /// The date the Shading was modified.
124    pub modified_at: NaiveDateTime,
125    /// The ID of the user who created the Shading.
126    pub created_by: Uuid,
127    /// The ID of the user who last modified the Shading.
128    pub modified_by: Uuid,
129}
130
131/// Used to update the `SoilTexture` entity.
132#[derive(Debug, Clone, Default, AsChangeset)]
133#[diesel(table_name = soil_textures)]
134pub struct UpdateSoilTexture {
135    pub id: Uuid,
136    pub soil_texture: Option<SoilTextureEnum>,
137    pub geometry: Option<Polygon<Point>>,
138    pub add_date: Option<Option<NaiveDate>>,
139    pub remove_date: Option<Option<NaiveDate>>,
140    pub notes: Option<String>,
141    pub modified_by: Uuid,
142}