backend/model/dto.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492
//! DTOs of `PermaplanT`.
#![allow(clippy::module_name_repetitions)] // There needs to be a difference between DTOs and entities otherwise imports will be messy.
use chrono::{NaiveDate, NaiveDateTime};
use postgis_diesel::types::{Point, Polygon};
use serde::{Deserialize, Serialize};
use typeshare::typeshare;
use utoipa::{IntoParams, ToSchema};
use uuid::Uuid;
use self::layers::LayerDto;
use super::r#enum::{
experience::Experience, include_archived_seeds::IncludeArchivedSeeds, life_cycle::LifeCycle,
membership::Membership, privacy_option::PrivacyOption, quality::Quality, quantity::Quantity,
salutation::Salutation, spatial_relation_type::SpatialRelationType,
};
pub mod actions;
pub mod application_settings_impl;
pub mod areas;
pub mod areas_impl;
pub mod base_layer_images;
pub mod base_layer_images_impl;
pub mod blossoms_impl;
pub mod coordinates_impl;
pub mod core;
pub mod drawings;
pub mod drawings_impl;
pub mod guided_tours_impl;
pub mod layer_impl;
pub mod layers;
pub mod map_collaborator_impl;
pub mod map_impl;
pub mod new_map_collaborator_impl;
pub mod new_map_impl;
pub mod new_seed_impl;
pub mod page_impl;
pub mod plantings;
pub mod plantings_impl;
pub mod plants_impl;
pub mod seed_impl;
pub mod timeline;
pub mod update_map_geometry_impl;
pub mod update_map_impl;
pub mod users_impl;
/// Contains configuration the frontend needs to run.
#[typeshare]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
pub struct ConfigDto {
/// The base URL of the authorization server
pub issuer_uri: String,
/// The client_id the frontend should use to log in
pub client_id: String,
/// The version must be an exact match between frontend and backend.
pub version: String,
}
/// Represents seeds of a user.
#[typeshare]
#[derive(Serialize, Deserialize, ToSchema)]
pub struct SeedDto {
/// The record id of the seed.
pub id: i32,
/// An additional name for the seed.
pub name: String,
/// The id of the plant this seed belongs to.
pub plant_id: Option<i32>,
/// When the seeds were harvested.
pub harvest_year: i16,
/// How many seeds there are.
pub quantity: Quantity,
/// When the seeds should be used by.
pub use_by: Option<NaiveDate>,
/// Where the seeds came from.
pub origin: Option<String>,
/// What the seeds taste like.
pub taste: Option<String>,
/// The yield of the seeds.
pub yield_: Option<String>,
/// How many generations the seeds have been grown.
pub generation: Option<i16>,
/// The quality of the seeds.
pub quality: Option<Quality>,
/// How much the seeds cost.
pub price: Option<i16>,
/// Notes about the seeds.
pub notes: Option<String>,
/// The id of the creator of the seed.
pub created_by: Uuid,
/// Timestamp indicating when the seed was archived.
/// Empty if the seed was not archived.
pub archived_at: Option<String>,
}
#[allow(clippy::missing_docs_in_private_items)] // TODO: See #97.
#[typeshare]
#[derive(Serialize, Deserialize, ToSchema)]
pub struct NewSeedDto {
pub name: String,
pub plant_id: Option<i32>,
pub harvest_year: i16,
pub quantity: Quantity,
pub use_by: Option<NaiveDate>,
pub origin: Option<String>,
pub taste: Option<String>,
pub yield_: Option<String>,
pub generation: Option<i16>,
pub quality: Option<Quality>,
pub price: Option<i16>,
pub notes: Option<String>,
}
/// Data that is required when archiving a seed.
#[typeshare]
#[derive(Serialize, Deserialize, ToSchema)]
pub struct ArchiveSeedDto {
/// Whether the seed should be archived.
pub archived: bool,
}
/// The essential identifying information of a plant.
#[typeshare]
#[derive(Debug, Serialize, PartialEq, Eq, Deserialize, ToSchema)]
pub struct PlantsSummaryDto {
/// The plants database id.
pub id: i32,
/// Biological name of this plant (E.g. "Triticum aestivum", "Prunus cerasus")
pub unique_name: String,
/// A list of common english names (E.g. "Bread wheat", "Sour cherry")
pub common_name_en: Option<Vec<Option<String>>>,
/// A list of common german names (E.g. "Brotweizen", "Sauerkirsche")
pub common_name_de: Option<Vec<Option<String>>>,
/// How far a plant spreads (The 'width' of a plant) in cm
pub spread: Option<i32>,
/// Indicates life span of the plant.
pub life_cycle: Vec<LifeCycle>,
}
/// Query parameters for searching plants.
#[typeshare]
#[derive(Debug, Deserialize, IntoParams)]
pub struct PlantsSearchParameters {
/// The system will check if this string occurs in the plants common name or unique name.
pub name: Option<String>,
}
/// Query parameters for searching spatial plant relations.
#[typeshare]
#[derive(Debug, Deserialize, IntoParams)]
pub struct RelationSearchParameters {
/// The id of the plant to find relations for.
pub plant_id: i32,
}
/// Use to return spatial relations for the plant.
#[typeshare]
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct RelationsDto {
/// The id of the plant in the relation.
pub id: i32,
/// The type of relation.
pub relations: Vec<RelationDto>,
}
/// Use to return a spatial relation.
#[typeshare]
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct RelationDto {
/// The id of the plant in the relation.
pub id: i32,
/// The type of relation.
pub relation: SpatialRelationType,
}
/// Query parameters for searching seeds.
#[typeshare]
#[derive(Debug, Deserialize, IntoParams)]
pub struct SeedSearchParameters {
/// Name of the seed to search for.
pub name: Option<String>,
/// The exact harvest year of the seed.
pub harvest_year: Option<i16>,
/// Whether archived, not archived or both kinds of seeds should be included.
/// If no value is provided, a default value of NotArchived is assumed.
pub archived: Option<IncludeArchivedSeeds>,
}
/// Query parameters paginating list endpoints.
#[typeshare]
#[derive(Debug, Deserialize, IntoParams)]
pub struct PageParameters {
/// Number of results in per page.
pub per_page: Option<i32>,
/// Page number to be returned.
/// Note: pages start at one.
pub page: Option<i32>,
}
/// A page of results returned from a list endpoint.
#[typeshare]
#[derive(Debug, Serialize, PartialEq, Eq, Deserialize, ToSchema)]
#[aliases(
PagePlantsSummaryDto = Page<PlantsSummaryDto>,
PageSeedDto = Page<SeedDto>,
PageMapDto = Page<MapDto>,
PageLayerDto = Page<LayerDto>
)]
pub struct Page<T> {
/// Resulting records.
pub results: Vec<T>,
/// Current page number.
pub page: i32,
/// Results per page.
pub per_page: i32,
/// Number of pages in total.
pub total_pages: i32,
}
/// The whole information of a map.
#[typeshare]
#[derive(Serialize, Deserialize, ToSchema)]
pub struct MapDto {
/// The id of the map.
pub id: i32,
/// The name of the map.
pub name: String,
/// When the map was created.
pub created_at: NaiveDateTime,
/// When a map was last modified, e.g by modifying plantings.
pub modified_at: NaiveDateTime,
/// The id of the creator of the map.
pub created_by: Uuid,
/// By whom the map was last modified.
pub modified_by: Uuid,
/// The date the map is supposed to be deleted.
pub deletion_date: Option<NaiveDate>,
/// The date the last time the map view was opened by any user.
pub last_visit: Option<NaiveDate>,
/// A flag indicating if this map is marked for deletion.
pub is_inactive: bool,
/// The zoom factor of the map.
pub zoom_factor: i16,
/// The amount of honors the map received.
pub honors: i16,
/// The amount of visits the map had.
pub visits: i16,
/// The amount of plants harvested on the map.
pub harvested: i16,
/// An enum indicating if this map is private or not.
pub privacy: PrivacyOption,
/// The description of the map.
pub description: Option<String>,
/// The location of the map as a latitude/longitude point.
pub location: Option<Coordinates>,
/// The geometry of the map.
///
/// E.g. `{"rings": [[{"x": 0.0,"y": 0.0},{"x": 1000.0,"y": 0.0},{"x": 1000.0,"y": 1000.0},{"x": 0.0,"y": 1000.0},{"x": 0.0,"y": 0.0}]],"srid": 4326}`
#[typeshare(serialized_as = "object")]
#[schema(value_type = Object)]
pub geometry: Polygon<Point>,
}
/// The information of a map necessary for its creation.
#[typeshare]
#[derive(Serialize, Deserialize, ToSchema)]
pub struct NewMapDto {
/// The name of the map.
pub name: String,
/// The date the map is supposed to be deleted.
pub deletion_date: Option<NaiveDate>,
/// The date the last time the map view was opened by any user.
pub last_visit: Option<NaiveDate>,
/// A flag indicating if this map is marked for deletion.
pub is_inactive: bool,
/// The zoom factor of the map.
pub zoom_factor: i16,
/// The amount of honors the map received.
pub honors: i16,
/// The amount of visits the map had.
pub visits: i16,
/// The amount of plants harvested on the map.
pub harvested: i16,
/// An enum indicating if this map is private or not.
pub privacy: PrivacyOption,
/// The description of the map.
pub description: Option<String>,
/// The location of the map as a latitude/longitude point.
pub location: Option<Coordinates>,
/// The geometry of the map.
///
/// E.g. `{"rings": [[{"x": 0.0,"y": 0.0},{"x": 1000.0,"y": 0.0},{"x": 1000.0,"y": 1000.0},{"x": 0.0,"y": 1000.0},{"x": 0.0,"y": 0.0}]],"srid": 4326}`
#[typeshare(serialized_as = "object")]
#[schema(value_type = Object)]
pub geometry: Polygon<Point>,
}
/// The information for updating a map.
#[typeshare]
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct UpdateMapDto {
/// The name of the map.
pub name: Option<String>,
/// An enum indicating if this map is private or not.
pub privacy: Option<PrivacyOption>,
/// The description of the map.
pub description: Option<String>,
/// The location of the map as a latitude/longitude point.
pub location: Option<Coordinates>,
}
/// Data for updating a maps geometry.
#[typeshare]
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct UpdateMapGeometryDto {
/// The geometry of the map.
///
/// E.g. `{"rings": [[{"x": 0.0,"y": 0.0},{"x": 1000.0,"y": 0.0},{"x": 1000.0,"y": 1000.0},{"x": 0.0,"y": 1000.0},{"x": 0.0,"y": 0.0}]],"srid": 4326}`
#[typeshare(serialized_as = "object")]
#[schema(value_type = Object)]
pub geometry: Polygon<Point>,
}
/// Query parameters for searching maps.
#[typeshare]
#[derive(Debug, Deserialize, IntoParams)]
pub struct MapSearchParameters {
/// Name of the map to search for.
pub name: Option<String>,
/// Whether or not the map is active.
pub is_inactive: Option<bool>,
/// The creator of the map.
pub created_by: Option<Uuid>,
/// The selected privacy of the map.
pub privacy: Option<PrivacyOption>,
}
/// Support struct for transmitting latitude/longitude coordinates.
#[typeshare]
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct Coordinates {
/// Latitude of the point.
pub latitude: f64,
/// Longitude of the point.
pub longitude: f64,
}
/// Query parameters for connecting to a map.
#[typeshare]
#[derive(Debug, Deserialize, IntoParams)]
pub struct ConnectToMapQueryParams {
/// The id of the map to connect to.
pub map_id: i32,
/// The id of the user connecting to the map.
pub user_id: String,
}
/// Query parameters to configure the generation of the heatmap.
#[typeshare]
#[derive(Debug, Deserialize, IntoParams)]
pub struct HeatMapQueryParams {
/// The id of the plant layer the planting will be planted on.
pub plant_layer_id: Uuid,
/// The id of the shade layer the planting will be planted on.
pub shade_layer_id: Uuid,
/// The id of the hydrology layer the planting will be planted on.
pub hydrology_layer_id: Uuid,
/// The id of the soil layer the planting will be planted on.
pub soil_layer_id: Uuid,
/// The id of the plant you want to plant.
pub plant_id: i32,
/// The date at which to generate the heatmap.
/// Will be set to the current date if `None`.
pub date: Option<NaiveDate>,
}
#[typeshare]
#[derive(Serialize, Deserialize, ToSchema)]
/// All of the application managed user data.
pub struct UsersDto {
/// The preferred salutation of the user.
pub salutation: Salutation,
/// The title(s) of the user.
pub title: Option<String>,
/// The current country of the user.
pub country: String,
/// The phone number of the user.
pub phone: Option<String>,
/// The website of the user.
pub website: Option<String>,
/// The organization the user belongs to.
pub organization: Option<String>,
/// The experience level in permaculture of the user.
pub experience: Option<Experience>,
/// The membership type of the user.
pub membership: Option<Membership>,
/// A collection of years in which the user was a member.
pub member_years: Option<Vec<Option<i32>>>,
/// The date since when the user is a member.
pub member_since: Option<NaiveDate>,
/// The amount of permacoins the user earned in each year as a member.
pub permacoins: Option<Vec<Option<i32>>>,
}
#[typeshare]
#[derive(Serialize, Deserialize, ToSchema)]
/// Completion status of all Guided Tours.
pub struct GuidedToursDto {
/// Whether or not the Map Editor Guided Tour was completed.
pub editor_tour_completed: bool,
}
#[typeshare]
#[derive(Serialize, Deserialize, ToSchema)]
/// The information for updating an users Guided Tour status.
pub struct UpdateGuidedToursDto {
/// Whether or not the Map Editor Guided Tour was completed.
pub editor_tour_completed: Option<bool>,
}
#[typeshare]
#[derive(Serialize, Deserialize, ToSchema)]
/// Information on a specific Blossom gained by a user.
pub struct GainedBlossomsDto {
/// The title of the Blossom.
pub blossom: String,
/// The number of times this Blossom was gained by this user.
pub times_gained: i32,
/// The date on which the user gained this Blossom.
pub gained_date: NaiveDate,
}
/// Application setting
#[typeshare]
#[derive(Serialize, Deserialize, ToSchema)]
pub struct ApplicationSettingDto {
/// The id of the setting
pub id: i32,
/// The unique key of the setting
pub key: String,
/// The value of the setting
pub value: String,
}
#[typeshare]
#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
/// Information on user collaborating on a map.
pub struct MapCollaboratorDto {
/// The id of the map.
pub map_id: i32,
/// The id of the collaborator.
pub user_id: Uuid,
/// The user name of the collaborator.
pub username: String,
}
#[typeshare]
#[derive(Debug, Deserialize, ToSchema)]
#[serde(rename_all = "camelCase")]
/// The information of a map collaborator necessary for its creation.
pub struct NewMapCollaboratorDto {
/// The id of the collaborator.
pub user_id: Uuid,
}
#[typeshare]
#[derive(Debug, Serialize, Deserialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct DeleteMapCollaboratorDto {
/// The id of the collaborator.
pub user_id: Uuid,
}
#[typeshare]
#[derive(Debug, Deserialize, IntoParams)]
#[serde(rename_all = "camelCase")]
/// Query params for searching map collaborators.
pub struct MapCollaboratorSearchParameters {
/// The id of the map.
pub map_id: i32,
}
#[typeshare]
#[derive(Debug, Deserialize, IntoParams)]
#[serde(rename_all = "camelCase")]
/// Query params for searching users.
pub struct UserSearchParameters {
/// The name of the user to search for.
pub username: String,
}