diff --git a/src/endpoints/events/get_new.rs b/src/endpoints/events/get_new.rs new file mode 100644 index 00000000..6754d470 --- /dev/null +++ b/src/endpoints/events/get_new.rs @@ -0,0 +1,38 @@ +use actix_identity::Identity; +use actix_web::{web, HttpResponse, Responder}; +use askama::Template; +use askama_actix::TemplateToResponse; +use chrono::NaiveDate; +use sqlx::PgPool; + +use crate::{endpoints::NaiveDateQuery, models::{Role, User, Location}}; + +#[derive(Template)] +#[template(path = "events/new.html")] +pub struct NewEventTemplate { + user: User, + date: NaiveDate, + locations: Vec +} + +#[actix_web::get("/events/new")] +pub async fn get(user: Identity, pool: web::Data, query: web::Query) -> impl Responder { + let current_user = User::read_by_id(pool.get_ref(), user.id().unwrap().parse().unwrap()) + .await + .unwrap(); + + if current_user.role != Role::Admin && current_user.role != Role::AreaManager { + return HttpResponse::Unauthorized().finish(); + } + + let locations; + if current_user.role == Role::Admin { + locations = Location::read_all_including_area(pool.get_ref()).await.unwrap(); + } else { + locations = Location::read_by_area(pool.get_ref(), current_user.area_id).await.unwrap(); + } + + let template = NewEventTemplate { user: current_user, date: query.date, locations }; + + return template.to_response(); +} diff --git a/src/endpoints/events/mod.rs b/src/endpoints/events/mod.rs new file mode 100644 index 00000000..661e73cf --- /dev/null +++ b/src/endpoints/events/mod.rs @@ -0,0 +1,2 @@ +pub mod get_new; +pub mod post_new; diff --git a/src/endpoints/events/post_new.rs b/src/endpoints/events/post_new.rs new file mode 100644 index 00000000..b4c9ef59 --- /dev/null +++ b/src/endpoints/events/post_new.rs @@ -0,0 +1,11 @@ +use actix_identity::Identity; +use actix_web::{web, HttpResponse, Responder}; +use sqlx::PgPool; + + + +#[actix_web::post("/events/new")] +pub async fn post(user: Identity, pool: web::Data) -> impl Responder { + + return HttpResponse::BadRequest().finish(); +} diff --git a/src/endpoints/mod.rs b/src/endpoints/mod.rs index 80fbf7f1..f67f3049 100644 --- a/src/endpoints/mod.rs +++ b/src/endpoints/mod.rs @@ -1,14 +1,21 @@ use actix_web::web::ServiceConfig; +use chrono::NaiveDate; use serde::Deserialize; mod location; mod user; +mod events; #[derive(Deserialize)] pub struct IdPath { pub id: i32 } +#[derive(Deserialize)] +pub struct NaiveDateQuery { + pub date: NaiveDate +} + pub fn init(cfg: &mut ServiceConfig) { cfg.service(location::get_overview::get); cfg.service(location::get_new::get); @@ -21,4 +28,7 @@ pub fn init(cfg: &mut ServiceConfig) { cfg.service(user::post_edit::post_edit); cfg.service(user::patch::patch); cfg.service(user::delete::delete); + + cfg.service(events::get_new::get); + // cfg.service(events::post_new::); } diff --git a/templates/events/new.html b/templates/events/new.html new file mode 100644 index 00000000..dd0a2e5f --- /dev/null +++ b/templates/events/new.html @@ -0,0 +1,118 @@ +{% extends "nav.html" %} + +{% block content %} +
+
+
+

Neues Event anlegen für den {{ date.format("%d.%m.%Y") }}

+ + + +
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+
+
+
+ +
+
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+ +
+
+ Zurück +
+
+
+
+ +
+
+
+ + +{% endblock %} diff --git a/templates/index.html b/templates/index.html index 24709759..034abf85 100644 --- a/templates/index.html +++ b/templates/index.html @@ -26,7 +26,7 @@