backend/model/dto/
timeline.rs

1use chrono::NaiveDate;
2use serde::{Deserialize, Serialize};
3use std::collections::HashMap;
4use typeshare::typeshare;
5use utoipa::{IntoParams, ToSchema};
6
7/// One summary datapoint in the timeline, used for a year, month or date
8#[typeshare]
9#[derive(Debug, Clone, Copy, Serialize, Deserialize, ToSchema, PartialEq, Eq)]
10#[serde(rename_all = "camelCase")]
11pub struct TimelineEntryDto {
12    pub additions: i32,
13    pub removals: i32,
14}
15
16/// Used to summerize the data necessary for the timeline
17#[typeshare]
18#[derive(Debug, Clone, Serialize, Deserialize, ToSchema, PartialEq, Eq)]
19#[serde(rename_all = "camelCase")]
20pub struct TimelineDto {
21    #[schema(example = "{ \"2020\": { \"additions\": 7, \"removals\": 7 } }")]
22    pub years: HashMap<String, TimelineEntryDto>,
23    #[schema(example = "{ \"2020-01\": { \"additions\": 7, \"removals\": 7 } }")]
24    pub months: HashMap<String, TimelineEntryDto>,
25    #[schema(
26        example = "{ \"2020-01-01\": { \"additions\": 3, \"removals\": 2 }, \"2020-01-05\": { \"additions\": 4, \"removals\": 5 } }"
27    )]
28    pub dates: HashMap<String, TimelineEntryDto>,
29}
30
31/// Query parameters for getting the timeline
32#[typeshare]
33#[derive(Debug, Deserialize, IntoParams)]
34#[serde(rename_all = "camelCase")]
35pub struct TimelineParameters {
36    /// Start date of the timeline
37    pub start: NaiveDate,
38    /// End date of the timeline
39    pub end: NaiveDate,
40}