backend/controller/
timeline.rsuse actix_web::{
get,
web::{Path, Query},
HttpResponse, Result,
};
use crate::service;
use crate::{config::data::SharedPool, model::dto::timeline::TimelineParameters};
#[utoipa::path(
context_path = "/api/maps/{map_id}/timeline",
params(
TimelineParameters
),
responses(
(status = 200, description = "Get timeline data from plantings", body = TimelineDto),
(status = 404, description = "Map not found", body = TimelineDto),
(status = 422, description = "Start is not smaller than end", body = TimelineDto)
),
security(
("oauth2" = [])
)
)]
#[get("timeline")]
pub async fn get_timeline(
map_id: Path<i32>,
parameters: Query<TimelineParameters>,
pool: SharedPool,
) -> Result<HttpResponse> {
let params = parameters.into_inner();
if params.start > params.end {
return Ok(HttpResponse::UnprocessableEntity().body("Start must be smaller than end"));
}
let dto = service::timeline::calculate(map_id.into_inner(), params, &pool).await?;
Ok(HttpResponse::Ok().json(dto))
}