From 74acc02e470c397da31ce80a2256d674ea4fa9bf Mon Sep 17 00:00:00 2001 From: Max Hohlfeld Date: Wed, 17 Apr 2024 07:00:55 +0200 Subject: [PATCH] feat: WIP new assignment --- src/endpoints/assignment/get_new.rs | 11 +++-- src/endpoints/assignment/mod.rs | 1 + src/endpoints/assignment/post_new.rs | 15 ++++++ src/models/assignement.rs | 19 ++++++++ src/models/availabillity.rs | 60 +++++++++++++++++++++++ src/models/function.rs | 2 +- src/models/mod.rs | 1 + templates/assignment/new.html | 73 ++++++++++++++++++++++++++++ 8 files changed, 178 insertions(+), 4 deletions(-) create mode 100644 src/endpoints/assignment/post_new.rs diff --git a/src/endpoints/assignment/get_new.rs b/src/endpoints/assignment/get_new.rs index dfe285a0..7ae579e6 100644 --- a/src/endpoints/assignment/get_new.rs +++ b/src/endpoints/assignment/get_new.rs @@ -5,7 +5,7 @@ use askama_actix::TemplateToResponse; use serde::Deserialize; use sqlx::PgPool; -use crate::models::{Event, Role, User}; +use crate::models::{Availabillity, Event, Function, Role, User}; #[derive(Deserialize)] pub struct EventQuery { @@ -16,7 +16,9 @@ pub struct EventQuery { #[template(path = "assignment/new.html")] pub struct NewAssignmentTemplate { user: User, - event: Event + event: Event, + available_wachhabende: Vec, + available_posten: Vec } #[actix_web::get("/assignments/new")] @@ -27,7 +29,10 @@ pub async fn get(user: Identity, pool: web::Data, query: web::Query, + posten: Vec +} + +#[actix_web::post("/assignments/new")] +pub async fn post(pool: web::Data, form: web::Form) -> impl Responder { + + HttpResponse::Ok().finish() +} diff --git a/src/models/assignement.rs b/src/models/assignement.rs index e69de29b..91c129d4 100644 --- a/src/models/assignement.rs +++ b/src/models/assignement.rs @@ -0,0 +1,19 @@ +use chrono::NaiveTime; +use sqlx::PgPool; + +use super::Function; + +pub struct Assignment { + pub event_id: i32, + pub availabillity_id: i32, + pub function: Function, + pub start_time: NaiveTime, + pub end_time: NaiveTime +} + +impl Assignment { + pub async fn create(pool: &PgPool) -> anyhow::Result { + + Ok(0) + } +} diff --git a/src/models/availabillity.rs b/src/models/availabillity.rs index abefc85b..2b4d9c9c 100644 --- a/src/models/availabillity.rs +++ b/src/models/availabillity.rs @@ -3,6 +3,7 @@ use sqlx::{query, PgPool}; use super::{function::Function, role::Role, user::User}; +#[derive(Clone)] pub struct Availabillity { pub id: i32, pub user_id: i32, @@ -117,6 +118,65 @@ impl Availabillity { Ok(availabillities) } + pub async fn read_not_assigned_by_date_including_user(pool: &PgPool, date: NaiveDate) -> anyhow::Result> { + let records = query!( + r##" + SELECT + availabillity.id, + availabillity.userId, + availabillity.date, + availabillity.startTime, + availabillity.endTime, + availabillity.comment, + user_.name, + user_.email, + user_.password, + user_.salt, + user_.role AS "role: Role", + user_.function AS "function: Function", + user_.areaId, + user_.locked, + user_.lastLogin, + user_.receiveNotifications + FROM availabillity + LEFT JOIN assignement ON availabillity.Id = assignement.availabillityId + JOIN user_ ON availabillity.userId = user_.id + WHERE availabillity.date = $1; + "##, + date + ) + .fetch_all(pool) + .await?; + + let availabillities = records + .iter() + .map(|r| Availabillity { + id: r.id, + user_id: r.userid, + user: Some(User { + id: r.userid, + name: r.name.clone(), + email: r.email.clone(), + password: r.password.clone(), + salt: r.salt.clone(), + role: r.role.clone(), + function: r.function.clone(), + area_id: r.areaid, + area: None, + locked: r.locked, + last_login: r.lastlogin, + receive_notifications: r.receivenotifications, + }), + date: r.date, + start_time: r.starttime, + end_time: r.endtime, + comment: r.comment.clone(), + }) + .collect(); + + Ok(availabillities) + } + pub async fn read_by_id(pool: &PgPool, id: i32) -> anyhow::Result { let record = query!("SELECT * FROM availabillity WHERE id = $1", id) .fetch_one(pool) diff --git a/src/models/function.rs b/src/models/function.rs index c7085959..7ea16ad7 100644 --- a/src/models/function.rs +++ b/src/models/function.rs @@ -1,6 +1,6 @@ use std::fmt::Display; -#[derive(sqlx::Type, Debug, Clone, Copy)] +#[derive(sqlx::Type, Debug, Clone, Copy, PartialEq, Eq)] #[sqlx(type_name = "function", rename_all = "lowercase")] pub enum Function { Posten = 1, diff --git a/src/models/mod.rs b/src/models/mod.rs index 9b760691..f9ef37c0 100644 --- a/src/models/mod.rs +++ b/src/models/mod.rs @@ -15,3 +15,4 @@ pub use function::Function; pub use location::Location; pub use role::Role; pub use user::User; +pub use assignement::Assignment; diff --git a/templates/assignment/new.html b/templates/assignment/new.html index 9337a95b..aef94601 100644 --- a/templates/assignment/new.html +++ b/templates/assignment/new.html @@ -5,6 +5,79 @@

Planung für {{ event.name }}

+
+ {% if event.canceled %}Veranstaltung abgesagt!{% endif %} +

Ort: {{ event.location.as_ref().unwrap().name }}

+

Zeitraum: {{ event.start_time }} bis {{ event.end_time }}

+

Anzahl der Posten: {{ event.amount_of_posten }}

+

Wachhabender durch FF gestellt: {{ event.voluntary_wachhabender }}

+

Kleidungsordnung: {{ event.clothing }}

+
+ + {% if event.voluntary_wachhabender %} +
+ +
+ +
+
+ {% endif %} + +
+ +
+ +
+
+ +
+ +
+ +
+