backend/model/entity/
areas.rs

1//! All area entities: `Shading`, `Hydrology` and `SoilTexture`
2
3use chrono::NaiveDate;
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}
36
37/// The `UpdateShading` entity.
38#[derive(Debug, Clone, Default, AsChangeset)]
39#[diesel(table_name = shadings)]
40pub struct UpdateShading {
41    pub id: Uuid,
42    pub shade: Option<Shade>,
43    pub geometry: Option<Polygon<Point>>,
44    pub add_date: Option<Option<NaiveDate>>,
45    pub remove_date: Option<Option<NaiveDate>>,
46    pub notes: Option<String>,
47}
48
49/// The `Hydrology` entity.
50#[derive(Debug, Clone, Identifiable, Queryable, Insertable)]
51#[diesel(table_name = hydrologies)]
52pub struct Hydrology {
53    /// The id of the hydrology.
54    pub id: Uuid,
55    /// The plant layer the hydrology is on.
56    pub layer_id: Uuid,
57    /// The water requirement.
58    pub water_requirement: WaterRequirementEnum,
59    /// The position of the hydrology on the map.
60    pub geometry: Polygon<Point>,
61    /// The date the hydrology was added to the map.
62    /// If None, the hydrology always existed.
63    pub add_date: Option<NaiveDate>,
64    /// The date the hydrology was removed from the map.
65    /// If None, the hydrology is still on the map.
66    pub remove_date: Option<NaiveDate>,
67    /// Markdown notes
68    pub notes: String,
69}
70
71/// The `UpdateHydrology` entity.
72#[derive(Debug, Clone, Default, AsChangeset)]
73#[diesel(table_name = hydrologies)]
74pub struct UpdateHydrology {
75    pub id: Uuid,
76    pub water_requirement: Option<WaterRequirementEnum>,
77    pub geometry: Option<Polygon<Point>>,
78    pub add_date: Option<Option<NaiveDate>>,
79    pub remove_date: Option<Option<NaiveDate>>,
80    pub notes: Option<String>,
81}
82
83/// The `SoilTexture` entity.
84#[derive(Debug, Clone, Identifiable, Queryable, Insertable)]
85#[diesel(table_name = soil_textures)]
86pub struct SoilTexture {
87    /// The id of the shading.
88    pub id: Uuid,
89    /// The plant layer the shadings is on.
90    pub layer_id: Uuid,
91    /// The kind of soil texture.
92    pub soil_texture: SoilTextureEnum,
93    /// The position of the shade on the map.
94    pub geometry: Polygon<Point>,
95    /// The date the shading was added to the map.
96    /// If None, the shading always existed.
97    pub add_date: Option<NaiveDate>,
98    /// The date the shading was removed from the map.
99    /// If None, the shading is still on the map.
100    pub remove_date: Option<NaiveDate>,
101    /// Markdown notes
102    pub notes: String,
103}
104
105/// Used to update the `SoilTexture` entity.
106#[derive(Debug, Clone, Default, AsChangeset)]
107#[diesel(table_name = soil_textures)]
108pub struct UpdateSoilTexture {
109    pub id: Uuid,
110    pub soil_texture: Option<SoilTextureEnum>,
111    pub geometry: Option<Polygon<Point>>,
112    pub add_date: Option<Option<NaiveDate>>,
113    pub remove_date: Option<Option<NaiveDate>>,
114    pub notes: Option<String>,
115}