backend/controller/
timeline.rs1use actix_web::{
4 get,
5 web::{Path, Query},
6 HttpResponse, Result,
7};
8
9use crate::service;
10use crate::{config::data::SharedPool, model::dto::timeline::TimelineParameters};
11
12#[utoipa::path(
20 context_path = "/api/maps/{map_id}/timeline",
21 params(
22 TimelineParameters
23 ),
24 responses(
25 (status = 200, description = "Get timeline data from plantings", body = TimelineDto),
26 (status = 404, description = "Map not found", body = TimelineDto),
27 (status = 422, description = "Start is not smaller than end", body = TimelineDto)
28 ),
29 security(
30 ("oauth2" = [])
31 )
32)]
33#[get("timeline")]
34pub async fn get_timeline(
35 map_id: Path<i32>,
36 parameters: Query<TimelineParameters>,
37 pool: SharedPool,
38) -> Result<HttpResponse> {
39 let params = parameters.into_inner();
40 if params.start > params.end {
41 return Ok(HttpResponse::UnprocessableEntity().body("Start must be smaller than end"));
42 }
43 let dto = service::timeline::calculate(map_id.into_inner(), params, &pool).await?;
44 Ok(HttpResponse::Ok().json(dto))
45}