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
//! Core DTO types, like wrappers.
//! Used by other modules of the dto module.

use chrono::NaiveDate;
use serde::{Deserialize, Serialize};
use typeshare::typeshare;
use utoipa::ToSchema;
use uuid::Uuid;

use crate::model::dto::{
    base_layer_images::{BaseLayerImageDto, DeleteBaseLayerImageDto, UpdateBaseLayerImageDto},
    drawings::{DrawingDto, UpdateDrawingsDto},
    layers::{DeleteLayerDto, LayerDto, UpdateLayerDto},
    plantings::{DeletePlantingDto, PlantingDto, UpdatePlantingDto},
};

/// A wrapper for a dto that is used to perform an action.
#[typeshare]
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
#[aliases(
    ActionDtoWrapperNewPlantings = ActionDtoWrapper<Vec<PlantingDto>>,
    ActionDtoWrapperUpdatePlantings = ActionDtoWrapper<UpdatePlantingDto>,
    ActionDtoWrapperDeletePlantings = ActionDtoWrapper<Vec<DeletePlantingDto>>,

    ActionDtoWrapperNewDrawings = ActionDtoWrapper<Vec<DrawingDto>>,
    ActionDtoWrapperUpdateDrawings = ActionDtoWrapper<UpdateDrawingsDto>,
    ActionDtoWrapperDeleteDrawings = ActionDtoWrapper<Vec<Uuid>>,

    ActionDtoWrapperNewLayer = ActionDtoWrapper<LayerDto>,
    ActionDtoWrapperUpdateLayer = ActionDtoWrapper<UpdateLayerDto>,
    ActionDtoWrapperDeleteLayer = ActionDtoWrapper<DeleteLayerDto>,

    ActionDtoWrapperNewBaseLayerImage = ActionDtoWrapper<BaseLayerImageDto>,
    ActionDtoWrapperUpdateBaseLayerImage = ActionDtoWrapper<UpdateBaseLayerImageDto>,
    ActionDtoWrapperDeleteBaseLayerImage = ActionDtoWrapper<DeleteBaseLayerImageDto>,

)]
#[serde(rename_all = "camelCase")]
pub struct ActionDtoWrapper<T> {
    pub action_id: Uuid,
    pub dto: T,
}

/// A page of results bounded by time.
#[typeshare]
#[derive(Debug, Serialize, Clone, Deserialize, ToSchema)]
#[aliases(
    TimelinePagePlantingsDto = TimelinePage<PlantingDto>,
)]
pub struct TimelinePage<T> {
    /// Resulting records.
    pub results: Vec<T>,
    /// The time frame start date.
    pub from: NaiveDate,
    /// The time frame end date.
    pub to: NaiveDate,
}