forked from Ruderverein-Donau-Linz/rowt
move managing events to own role
This commit is contained in:
@ -10,7 +10,7 @@ use sqlx::SqlitePool;
|
||||
use crate::model::{
|
||||
planned_event::PlannedEvent,
|
||||
tripdetails::{TripDetails, TripDetailsToAdd},
|
||||
user::AdminUser,
|
||||
user::PlannedEventUser,
|
||||
};
|
||||
|
||||
//TODO: add constraints (e.g. planned_amount_cox > 0)
|
||||
@ -25,7 +25,7 @@ struct AddPlannedEventForm<'r> {
|
||||
async fn create(
|
||||
db: &State<SqlitePool>,
|
||||
data: Form<AddPlannedEventForm<'_>>,
|
||||
_admin: AdminUser,
|
||||
_admin: PlannedEventUser,
|
||||
) -> Flash<Redirect> {
|
||||
let data = data.into_inner();
|
||||
|
||||
@ -36,7 +36,7 @@ async fn create(
|
||||
|
||||
PlannedEvent::create(db, data.name, data.planned_amount_cox, trip_details).await;
|
||||
|
||||
Flash::success(Redirect::to("/"), "Event hinzugefügt")
|
||||
Flash::success(Redirect::to("/planned"), "Event hinzugefügt")
|
||||
}
|
||||
|
||||
//TODO: add constraints (e.g. planned_amount_cox > 0)
|
||||
@ -54,7 +54,7 @@ struct UpdatePlannedEventForm<'r> {
|
||||
async fn update(
|
||||
db: &State<SqlitePool>,
|
||||
data: Form<UpdatePlannedEventForm<'_>>,
|
||||
_admin: AdminUser,
|
||||
_admin: PlannedEventUser,
|
||||
) -> Flash<Redirect> {
|
||||
match PlannedEvent::find_by_id(db, data.id).await {
|
||||
Some(planned_event) => {
|
||||
@ -68,20 +68,20 @@ async fn update(
|
||||
data.is_locked,
|
||||
)
|
||||
.await;
|
||||
Flash::success(Redirect::to("/"), "Successfully edited the event")
|
||||
Flash::success(Redirect::to("/planned"), "Event erfolgreich bearbeitet")
|
||||
}
|
||||
None => Flash::error(Redirect::to("/"), "Planned event id not found"),
|
||||
None => Flash::error(Redirect::to("/planned"), "Planned event id not found"),
|
||||
}
|
||||
}
|
||||
|
||||
#[get("/planned-event/<id>/delete")]
|
||||
async fn delete(db: &State<SqlitePool>, id: i64, _admin: AdminUser) -> Flash<Redirect> {
|
||||
async fn delete(db: &State<SqlitePool>, id: i64, _admin: PlannedEventUser) -> Flash<Redirect> {
|
||||
match PlannedEvent::find_by_id(db, id).await {
|
||||
Some(planned_event) => {
|
||||
planned_event.delete(db).await;
|
||||
Flash::success(Redirect::to("/"), "Event gelöscht")
|
||||
Flash::success(Redirect::to("/planned"), "Event gelöscht")
|
||||
}
|
||||
None => Flash::error(Redirect::to("/"), "PlannedEvent does not exist"),
|
||||
None => Flash::error(Redirect::to("/planned"), "PlannedEvent does not exist"),
|
||||
}
|
||||
}
|
||||
|
||||
@ -120,7 +120,7 @@ mod test {
|
||||
let response = req.dispatch().await;
|
||||
|
||||
assert_eq!(response.status(), Status::SeeOther);
|
||||
assert_eq!(response.headers().get("Location").next(), Some("/"));
|
||||
assert_eq!(response.headers().get("Location").next(), Some("/planned"));
|
||||
|
||||
let flash_cookie = response
|
||||
.cookies()
|
||||
@ -151,7 +151,7 @@ mod test {
|
||||
let response = req.dispatch().await;
|
||||
|
||||
assert_eq!(response.status(), Status::SeeOther);
|
||||
assert_eq!(response.headers().get("Location").next(), Some("/"));
|
||||
assert_eq!(response.headers().get("Location").next(), Some("/planned"));
|
||||
|
||||
let flash_cookie = response
|
||||
.cookies()
|
||||
@ -187,7 +187,7 @@ mod test {
|
||||
let response = req.dispatch().await;
|
||||
|
||||
assert_eq!(response.status(), Status::SeeOther);
|
||||
assert_eq!(response.headers().get("Location").next(), Some("/"));
|
||||
assert_eq!(response.headers().get("Location").next(), Some("/planned"));
|
||||
|
||||
let flash_cookie = response
|
||||
.cookies()
|
||||
@ -196,7 +196,7 @@ mod test {
|
||||
|
||||
assert_eq!(
|
||||
flash_cookie.value(),
|
||||
"7:successSuccessfully edited the event"
|
||||
"7:successEvent erfolgreich bearbeitet"
|
||||
);
|
||||
|
||||
let event = PlannedEvent::find_by_id(&db, 1).await.unwrap();
|
||||
@ -224,7 +224,7 @@ mod test {
|
||||
let response = req.dispatch().await;
|
||||
|
||||
assert_eq!(response.status(), Status::SeeOther);
|
||||
assert_eq!(response.headers().get("Location").next(), Some("/"));
|
||||
assert_eq!(response.headers().get("Location").next(), Some("/planned"));
|
||||
|
||||
let flash_cookie = response
|
||||
.cookies()
|
||||
@ -255,7 +255,7 @@ mod test {
|
||||
let response = req.dispatch().await;
|
||||
|
||||
assert_eq!(response.status(), Status::SeeOther);
|
||||
assert_eq!(response.headers().get("Location").next(), Some("/"));
|
||||
assert_eq!(response.headers().get("Location").next(), Some("/planned"));
|
||||
|
||||
let flash_cookie = response
|
||||
.cookies()
|
||||
|
Reference in New Issue
Block a user