backend/service/
timeline.rs

1use crate::{
2    config::data::SharedPool,
3    error::ServiceError,
4    model::{
5        dto::timeline::{TimelineDto, TimelineParameters},
6        entity::{timeline, Map},
7    },
8};
9
10/// Summarizes the all additions and removals of plantings
11/// between `params.start` and `params.end`.
12///
13/// # Errors
14/// If the connection to the database could not be established.
15pub async fn calculate(
16    map_id: i32,
17    params: TimelineParameters,
18    pool: &SharedPool,
19) -> Result<TimelineDto, ServiceError> {
20    let mut conn = pool.get().await?;
21    // Check if the map exists
22    Map::find_by_id(map_id, &mut conn).await?;
23    let result = timeline::calculate(map_id, params, &mut conn).await?;
24    Ok(result)
25}