aboutsummaryrefslogtreecommitdiffstats
path: root/src/controllers/event.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/controllers/event.rs')
-rw-r--r--src/controllers/event.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/controllers/event.rs b/src/controllers/event.rs
index eca8c21..c7ac4d3 100644
--- a/src/controllers/event.rs
+++ b/src/controllers/event.rs
@@ -92,3 +92,23 @@ pub async fn edit(db: db::Connection, eventid: i32) -> Result<Template, Status>
Ok(Template::render("event/edit", Context { event }))
}
+
+#[derive(FromForm)]
+pub struct EditEventForm {
+ pub id: i32,
+ pub name: String,
+ pub description: String,
+}
+
+#[post("/<eventid>/update", format = "application/x-www-form-urlencoded", data = "<form>")]
+pub async fn update(db: db::Connection, eventid: i32, form: Form<EditEventForm>) -> Result<Redirect, Status> {
+ if eventid != form.id {
+ return Err(Status::BadRequest);
+ }
+
+ models::Event::update(&db, eventid, form.name.to_owned(), form.description.to_owned())
+ .await
+ .map_err(|_| Status::InternalServerError)?;
+
+ Ok(Redirect::to("/"))
+}