feat: add basic planning for event
This commit is contained in:
parent
9959936f51
commit
1915baf094
39
src/endpoints/assignment/get_new.rs
Normal file
39
src/endpoints/assignment/get_new.rs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
use actix_identity::Identity;
|
||||||
|
use actix_web::{web, HttpResponse, Responder};
|
||||||
|
use askama::Template;
|
||||||
|
use askama_actix::TemplateToResponse;
|
||||||
|
use serde::Deserialize;
|
||||||
|
use sqlx::PgPool;
|
||||||
|
|
||||||
|
use crate::models::{Event, Role, User};
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct EventQuery {
|
||||||
|
event: i32
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Template)]
|
||||||
|
#[template(path = "assignment/new.html")]
|
||||||
|
pub struct NewAssignmentTemplate {
|
||||||
|
user: User,
|
||||||
|
event: Event
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix_web::get("/assignments/new")]
|
||||||
|
pub async fn get(user: Identity, pool: web::Data<PgPool>, query: web::Query<EventQuery>) -> impl Responder {
|
||||||
|
let current_user = User::read_by_id(pool.get_ref(), user.id().unwrap().parse().unwrap())
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
if let Ok(event) = Event::read_by_id_including_location(pool.get_ref(), query.event).await {
|
||||||
|
if current_user.role == Role::Admin || current_user.role == Role::AreaManager && event.location.as_ref().unwrap().area_id == current_user.area_id {
|
||||||
|
let template = NewAssignmentTemplate { user: current_user, event };
|
||||||
|
|
||||||
|
return template.to_response();
|
||||||
|
}
|
||||||
|
|
||||||
|
return HttpResponse::Unauthorized().finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpResponse::BadRequest().body("Fehler beim Laden für Assignment")
|
||||||
|
}
|
1
src/endpoints/assignment/mod.rs
Normal file
1
src/endpoints/assignment/mod.rs
Normal file
@ -0,0 +1 @@
|
|||||||
|
pub mod get_new;
|
@ -5,6 +5,7 @@ use serde::Deserialize;
|
|||||||
mod events;
|
mod events;
|
||||||
mod location;
|
mod location;
|
||||||
mod user;
|
mod user;
|
||||||
|
mod assignment;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct IdPath {
|
pub struct IdPath {
|
||||||
@ -31,4 +32,6 @@ pub fn init(cfg: &mut ServiceConfig) {
|
|||||||
|
|
||||||
cfg.service(events::get_new::get);
|
cfg.service(events::get_new::get);
|
||||||
cfg.service(events::post_new::post);
|
cfg.service(events::post_new::post);
|
||||||
|
|
||||||
|
cfg.service(assignment::get_new::get);
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ impl Event {
|
|||||||
id: record.locationid,
|
id: record.locationid,
|
||||||
name: record.locationname.to_string(),
|
name: record.locationname.to_string(),
|
||||||
area_id: record.locationareaid,
|
area_id: record.locationareaid,
|
||||||
area: None
|
area: None,
|
||||||
}),
|
}),
|
||||||
voluntary_wachhabender: record.voluntarywachhabender,
|
voluntary_wachhabender: record.voluntarywachhabender,
|
||||||
amount_of_posten: record.amountofposten,
|
amount_of_posten: record.amountofposten,
|
||||||
@ -112,4 +112,52 @@ impl Event {
|
|||||||
|
|
||||||
Ok(events)
|
Ok(events)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn read_by_id_including_location(pool: &PgPool, id: i32) -> anyhow::Result<Event> {
|
||||||
|
let record = query!(
|
||||||
|
r#"
|
||||||
|
SELECT
|
||||||
|
event.id AS eventId,
|
||||||
|
event.date,
|
||||||
|
event.startTime,
|
||||||
|
event.endTime,
|
||||||
|
event.name,
|
||||||
|
event.locationId,
|
||||||
|
event.voluntaryWachhabender,
|
||||||
|
event.amountOfPosten,
|
||||||
|
event.clothing,
|
||||||
|
event.canceled,
|
||||||
|
location.id,
|
||||||
|
location.name AS locationName,
|
||||||
|
location.areaId AS locationAreaId
|
||||||
|
FROM event
|
||||||
|
JOIN location ON event.locationId = location.id
|
||||||
|
WHERE event.id = $1;
|
||||||
|
"#,
|
||||||
|
id
|
||||||
|
)
|
||||||
|
.fetch_one(pool)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let event = Event {
|
||||||
|
id: record.eventid,
|
||||||
|
date: record.date,
|
||||||
|
start_time: record.starttime,
|
||||||
|
end_time: record.endtime,
|
||||||
|
name: record.name.to_string(),
|
||||||
|
location_id: record.locationid,
|
||||||
|
location: Some(Location {
|
||||||
|
id: record.locationid,
|
||||||
|
name: record.locationname.to_string(),
|
||||||
|
area_id: record.locationareaid,
|
||||||
|
area: None,
|
||||||
|
}),
|
||||||
|
voluntary_wachhabender: record.voluntarywachhabender,
|
||||||
|
amount_of_posten: record.amountofposten,
|
||||||
|
clothing: record.clothing.to_string(),
|
||||||
|
canceled: record.canceled,
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(event)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
15
templates/assignment/new.html
Normal file
15
templates/assignment/new.html
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{% extends "nav.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<section class="section">
|
||||||
|
<div class="container">
|
||||||
|
<form method="post" action="/users/new">
|
||||||
|
<h1 class="title">Planung für {{ event.name }}</h1>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
@ -41,7 +41,7 @@
|
|||||||
<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">
|
||||||
<a href="" 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>
|
||||||
</span>
|
</span>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user