54 lines
1.5 KiB
Rust
54 lines
1.5 KiB
Rust
use actix_web::{web, Responder};
|
|
use chrono::NaiveTime;
|
|
use sqlx::PgPool;
|
|
|
|
use crate::{
|
|
endpoints::{events::NewOrEditEventTemplate, NaiveDateQuery},
|
|
utils::{ApplicationError, TemplateResponse},
|
|
};
|
|
use brass_db::models::{Clothing, Location, Role, User};
|
|
|
|
#[actix_web::get("/events/new")]
|
|
pub async fn get(
|
|
user: web::ReqData<User>,
|
|
pool: web::Data<PgPool>,
|
|
query: web::Query<NaiveDateQuery>,
|
|
) -> Result<impl Responder, ApplicationError> {
|
|
if user.role != Role::Admin && user.role != Role::AreaManager {
|
|
return Err(ApplicationError::Unauthorized);
|
|
}
|
|
|
|
let locations = if user.role == Role::Admin {
|
|
Location::read_all_including_area(pool.get_ref()).await?
|
|
} else {
|
|
Location::read_by_area(pool.get_ref(), user.area_id).await?
|
|
};
|
|
|
|
let clothing_options = Clothing::read_all(pool.get_ref()).await?;
|
|
|
|
let template = NewOrEditEventTemplate {
|
|
user: user.into_inner(),
|
|
date: query.date,
|
|
locations,
|
|
amount_of_planned_posten: 0,
|
|
is_fuehrungsassistent_planned: false,
|
|
is_wachhabender_planned: false,
|
|
id: None,
|
|
start: NaiveTime::from_hms_opt(18, 0, 0).unwrap(),
|
|
end: query
|
|
.date
|
|
.and_time(NaiveTime::from_hms_opt(23, 00, 00).unwrap()),
|
|
name: None,
|
|
location: None,
|
|
voluntary_wachhabender: false,
|
|
voluntary_fuehrungsassistent: false,
|
|
amount_of_posten: None,
|
|
clothing: None,
|
|
clothing_options,
|
|
canceled: false,
|
|
note: None,
|
|
};
|
|
|
|
Ok(template.to_response()?)
|
|
}
|