51 lines
1.4 KiB
Rust
51 lines
1.4 KiB
Rust
use askama::Template;
|
|
use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
|
|
use serde::Deserialize;
|
|
|
|
use crate::filters;
|
|
use crate::models::{Availability, AvailabilityChangeset, Role, User};
|
|
use crate::utils::DateTimeFormat::{DayMonth, DayMonthYear, DayMonthYearHourMinute, HourMinute};
|
|
|
|
pub mod delete;
|
|
pub mod get_new;
|
|
pub mod get_overview;
|
|
pub mod get_update;
|
|
pub mod post_new;
|
|
pub mod post_update;
|
|
|
|
#[derive(Template)]
|
|
#[template(path = "availability/new_or_edit.html")]
|
|
struct NewOrEditAvailabilityTemplate<'a> {
|
|
user: User,
|
|
date: NaiveDate,
|
|
enddate: Option<NaiveDate>,
|
|
id: Option<i32>,
|
|
start: Option<NaiveTime>,
|
|
end: Option<NaiveTime>,
|
|
comment: Option<&'a str>,
|
|
slot_suggestions: Vec<(NaiveDateTime, NaiveDateTime)>,
|
|
datetomorrow: NaiveDate,
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct AvailabilityForm {
|
|
pub startdate: NaiveDate,
|
|
pub enddate: NaiveDate,
|
|
pub starttime: NaiveTime,
|
|
pub endtime: NaiveTime,
|
|
pub comment: Option<String>,
|
|
}
|
|
|
|
fn find_adjacend_availability<'a>(
|
|
changeset: &AvailabilityChangeset,
|
|
availability_id_to_be_updated: Option<i32>,
|
|
existing_availabilities: &'a [Availability],
|
|
) -> Option<&'a Availability> {
|
|
let existing_availability = existing_availabilities
|
|
.iter()
|
|
.filter(|a| availability_id_to_be_updated.is_none_or(|id| a.id != id))
|
|
.find(|a| a.start == changeset.time.1 || a.end == changeset.time.0);
|
|
|
|
return existing_availability;
|
|
}
|