47 lines
1.2 KiB
Rust
47 lines
1.2 KiB
Rust
use chrono::{NaiveDate, NaiveTime};
|
|
use rinja::Template;
|
|
|
|
use crate::filters;
|
|
use crate::models::{Availability, AvailabilityChangeset, AvailabilityTime, Role, User};
|
|
|
|
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,
|
|
id: Option<i32>,
|
|
time_selection: AvailabilityTime,
|
|
comment: Option<&'a str>,
|
|
slot_suggestions: Vec<(NaiveTime, NaiveTime)>,
|
|
}
|
|
|
|
fn find_adjacend_availability<'a>(
|
|
changeset: &AvailabilityChangeset,
|
|
availability_id_to_be_updated: Option<i32>,
|
|
existing_availabilities: &'a [Availability],
|
|
) -> Option<&'a Availability> {
|
|
let AvailabilityTime::Temporarily(changeset_start, changeset_end) = changeset.time else {
|
|
return None;
|
|
};
|
|
|
|
for a in existing_availabilities
|
|
.iter()
|
|
.filter(|a| availability_id_to_be_updated.is_none_or(|id| a.id != id))
|
|
{
|
|
if let AvailabilityTime::Temporarily(start, end) = a.time {
|
|
if start == changeset_end || end == changeset_start {
|
|
return Some(a);
|
|
}
|
|
}
|
|
}
|
|
|
|
None
|
|
}
|