feat: creation of assignments works
This commit is contained in:
parent
564d1b5946
commit
53b50a153c
@ -12,17 +12,20 @@ pub struct NewAssignmentsForm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[actix_web::post("/assignments/new")]
|
#[actix_web::post("/assignments/new")]
|
||||||
pub async fn post(pool: web::Data<PgPool>, form: web::Form<NewAssignmentsForm>) -> impl Responder {
|
pub async fn post(pool: web::Data<PgPool>, form: web::Form<Vec<(String, String)>>) -> impl Responder {
|
||||||
|
let event_id = form.iter().find(|x| x.0 == "event").unwrap().1.parse().unwrap();
|
||||||
|
let wachhabender = form.iter().find(|x| x.0 == "wachhabender");
|
||||||
|
let posten: Vec<i32> = form.iter().filter(|x| x.0 == "posten").map(|x| x.1.parse().unwrap()).collect();
|
||||||
|
|
||||||
let event = Event::read_by_id_including_location(&pool, form.event).await.unwrap(); // TODO: Check if location is needed
|
let event = Event::read_by_id_including_location(&pool, event_id).await.unwrap(); // TODO: Check if location is needed
|
||||||
|
|
||||||
if event.voluntary_wachhabender && form.wachhabender.is_some() && form.posten.contains(&form.wachhabender.unwrap()) {
|
if event.voluntary_wachhabender && wachhabender.is_some() && posten.contains(&wachhabender.unwrap().1.parse().unwrap()) {
|
||||||
return HttpResponse::BadRequest().body("Wachhabender kann nicht zugleich Posten sein!");
|
return HttpResponse::BadRequest().body("Wachhabender kann nicht zugleich Posten sein!");
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut joined_ids = form.posten.clone();
|
let mut joined_ids = posten.clone();
|
||||||
if let Some(id) = form.wachhabender {
|
if let Some((_,id)) = wachhabender {
|
||||||
joined_ids.push(id);
|
joined_ids.push(id.parse().unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
for availabillity_id in joined_ids {
|
for availabillity_id in joined_ids {
|
||||||
@ -30,8 +33,10 @@ pub async fn post(pool: web::Data<PgPool>, form: web::Form<NewAssignmentsForm>)
|
|||||||
|
|
||||||
let mut can_be_used = true;
|
let mut can_be_used = true;
|
||||||
|
|
||||||
|
|
||||||
for assignment in assignments {
|
for assignment in assignments {
|
||||||
if event.start_time >= assignment.start_time && event.start_time <= assignment.end_time {
|
if event.start_time >= assignment.start_time && event.start_time <= assignment.end_time {
|
||||||
|
} else {
|
||||||
can_be_used = false;
|
can_be_used = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -42,12 +47,12 @@ pub async fn post(pool: web::Data<PgPool>, form: web::Form<NewAssignmentsForm>)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(id) = form.wachhabender {
|
if let Some((_,id)) = wachhabender {
|
||||||
Assignment::create(pool.get_ref(), id, event.id, Function::Wachhabender, event.start_time, event.end_time).await.unwrap();
|
Assignment::create(pool.get_ref(), event.id, id.parse().unwrap(), Function::Wachhabender, event.start_time, event.end_time).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
for id in &form.posten {
|
for id in posten {
|
||||||
Assignment::create(pool.get_ref(), *id, event.id, Function::Posten, event.start_time, event.end_time).await.unwrap();
|
Assignment::create(pool.get_ref(), event.id, id, Function::Posten, event.start_time, event.end_time).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpResponse::Ok().finish()
|
HttpResponse::Ok().finish()
|
||||||
|
@ -37,4 +37,5 @@ pub fn init(cfg: &mut ServiceConfig) {
|
|||||||
cfg.service(events::post_new::post);
|
cfg.service(events::post_new::post);
|
||||||
|
|
||||||
cfg.service(assignment::get_new::get);
|
cfg.service(assignment::get_new::get);
|
||||||
|
cfg.service(assignment::post_new::post);
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,8 @@ pub struct Assignment {
|
|||||||
impl Assignment {
|
impl Assignment {
|
||||||
pub async fn create(
|
pub async fn create(
|
||||||
pool: &PgPool,
|
pool: &PgPool,
|
||||||
availabillity_id: i32,
|
|
||||||
event_id: i32,
|
event_id: i32,
|
||||||
|
availabillity_id: i32,
|
||||||
function: Function,
|
function: Function,
|
||||||
start_time: NaiveTime,
|
start_time: NaiveTime,
|
||||||
end_time: NaiveTime,
|
end_time: NaiveTime,
|
||||||
@ -25,8 +25,8 @@ impl Assignment {
|
|||||||
INSERT INTO assignment (eventId, availabillityId, function, startTime, endTime)
|
INSERT INTO assignment (eventId, availabillityId, function, startTime, endTime)
|
||||||
VALUES ($1, $2, $3, $4, $5);
|
VALUES ($1, $2, $3, $4, $5);
|
||||||
"##,
|
"##,
|
||||||
availabillity_id,
|
|
||||||
event_id,
|
event_id,
|
||||||
|
availabillity_id,
|
||||||
function as Function,
|
function as Function,
|
||||||
start_time,
|
start_time,
|
||||||
end_time
|
end_time
|
||||||
|
@ -41,9 +41,11 @@
|
|||||||
<div class="level">
|
<div class="level">
|
||||||
<h5 class="title is-5 level-left">{{ event.name }}</h5>
|
<h5 class="title is-5 level-left">{{ event.name }}</h5>
|
||||||
<span class ="level-right">
|
<span class ="level-right">
|
||||||
|
{% if user.role == Role::AreaManager || user.role == Role::Admin %}
|
||||||
<a href="/assignments/new?event={{ event.id }}" class="button is-primary level-item">Planen</a>
|
<a href="/assignments/new?event={{ event.id }}" class="button is-primary level-item">Planen</a>
|
||||||
<a href="" class="button is-primary-light level-item">bearbeiten</a>
|
<a href="" class="button is-primary-light level-item">bearbeiten</a>
|
||||||
<a href="" class="button is-warning level-item">als abgesagt markieren</a>
|
<a href="" class="button is-warning level-item">als abgesagt markieren</a>
|
||||||
|
{% endif %}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<p>Ort: {{ event.location.as_ref().unwrap().name }}</p>
|
<p>Ort: {{ event.location.as_ref().unwrap().name }}</p>
|
||||||
@ -88,11 +90,11 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for availabillity in availabillities %}
|
{% for availabillity in availabillities %}
|
||||||
{% let user = availabillity.user.as_ref().unwrap() %}
|
{% let u = availabillity.user.as_ref().unwrap() %}
|
||||||
<tr id="availabillity-{{ availabillity.id }}">
|
<tr id="availabillity-{{ availabillity.id }}">
|
||||||
<td>{{ user.name }}</td>
|
<td>{{ u.name }}</td>
|
||||||
<td>
|
<td>
|
||||||
{% match user.function %}
|
{% match u.function %}
|
||||||
{% when Function::Posten %}
|
{% when Function::Posten %}
|
||||||
<span class="tag is-info is-light">Posten</span>
|
<span class="tag is-info is-light">Posten</span>
|
||||||
{% when Function::Wachhabender %}
|
{% when Function::Wachhabender %}
|
||||||
|
@ -48,7 +48,8 @@
|
|||||||
|
|
||||||
<div class="navbar-end">
|
<div class="navbar-end">
|
||||||
<div class="navbar-item">
|
<div class="navbar-item">
|
||||||
<div class="buttons">
|
angemeldet als {{ user.name }}
|
||||||
|
<div class="buttons ml-3">
|
||||||
<a class="button is-primary">
|
<a class="button is-primary">
|
||||||
Profil
|
Profil
|
||||||
</a>
|
</a>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user