backend/model/dto/
core.rs

1//! Core DTO types, like wrappers.
2//! Used by other modules of the dto module.
3
4use chrono::NaiveDate;
5use serde::{Deserialize, Serialize};
6use typeshare::typeshare;
7use utoipa::ToSchema;
8use uuid::Uuid;
9
10use crate::model::dto::{
11    areas::{NewAreaDto, UpdateAreaDto},
12    base_layer_images::{BaseLayerImageDto, DeleteBaseLayerImageDto, UpdateBaseLayerImageDto},
13    drawings::{DrawingDto, UpdateDrawingsDto},
14    layers::{DeleteLayerDto, LayerDto, UpdateLayerDto},
15    plantings::{DeletePlantingDto, PlantingDto, UpdatePlantingDto},
16};
17
18/// A wrapper for a dto that is used to perform an action.
19#[typeshare]
20#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
21#[aliases(
22    ActionDtoWrapperNewPlantings = ActionDtoWrapper<Vec<PlantingDto>>,
23    ActionDtoWrapperUpdatePlantings = ActionDtoWrapper<UpdatePlantingDto>,
24    ActionDtoWrapperDeletePlantings = ActionDtoWrapper<Vec<DeletePlantingDto>>,
25
26    ActionDtoWrapperNewDrawings = ActionDtoWrapper<Vec<DrawingDto>>,
27    ActionDtoWrapperUpdateDrawings = ActionDtoWrapper<UpdateDrawingsDto>,
28    ActionDtoWrapperDeleteDrawings = ActionDtoWrapper<Vec<Uuid>>,
29
30    ActionDtoWrapperNewAreas = ActionDtoWrapper<Vec<NewAreaDto>>,
31    ActionDtoWrapperUpdateAreas = ActionDtoWrapper<UpdateAreaDto>,
32    ActionDtoWrapperDeleteAreas = ActionDtoWrapper<Vec<Uuid>>,
33
34    ActionDtoWrapperNewLayer = ActionDtoWrapper<LayerDto>,
35    ActionDtoWrapperUpdateLayer = ActionDtoWrapper<UpdateLayerDto>,
36    ActionDtoWrapperDeleteLayer = ActionDtoWrapper<DeleteLayerDto>,
37
38    ActionDtoWrapperNewBaseLayerImage = ActionDtoWrapper<BaseLayerImageDto>,
39    ActionDtoWrapperUpdateBaseLayerImage = ActionDtoWrapper<UpdateBaseLayerImageDto>,
40    ActionDtoWrapperDeleteBaseLayerImage = ActionDtoWrapper<DeleteBaseLayerImageDto>,
41
42)]
43#[serde(rename_all = "camelCase")]
44pub struct ActionDtoWrapper<T> {
45    pub action_id: Uuid,
46    pub dto: T,
47}
48
49/// A page of results bounded by time.
50#[typeshare]
51#[derive(Debug, Serialize, Clone, Deserialize, ToSchema)]
52#[aliases(
53    TimelinePagePlantingsDto = TimelinePage<PlantingDto>,
54)]
55pub struct TimelinePage<T> {
56    /// Resulting records.
57    pub results: Vec<T>,
58    /// The time frame start date.
59    pub from: NaiveDate,
60    /// The time frame end date.
61    pub to: NaiveDate,
62}