diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2021-08-25 20:54:15 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2021-08-25 20:54:15 +0200 |
commit | 7b33c425e89a214a55a32a24bd37d4dc9f729509 (patch) | |
tree | 3de7ff07748dcbf860ee6d0d1a9b63faf29ec4db /src/controllers | |
parent | 4fa322a49f1a24e86786ff8c0e7cf8a42797f61e (diff) | |
download | ramaskrik-social-7b33c425e89a214a55a32a24bd37d4dc9f729509.tar.gz ramaskrik-social-7b33c425e89a214a55a32a24bd37d4dc9f729509.tar.bz2 ramaskrik-social-7b33c425e89a214a55a32a24bd37d4dc9f729509.zip |
Implement update events.dev
Diffstat (limited to 'src/controllers')
-rw-r--r-- | src/controllers/event.rs | 20 |
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("/")) +} |