diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2020-08-22 20:14:03 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2020-08-22 20:14:03 +0200 |
commit | 701ff00b72b423b77e3d1e09dc7fc1b817b207cb (patch) | |
tree | b1914d2b292aa3462ffb3dff7856d7436469da28 /src/controllers | |
parent | 86178bb3a5ad131766a57cdcac9f22fed3c55f8a (diff) | |
download | ramaskrik-social-701ff00b72b423b77e3d1e09dc7fc1b817b207cb.tar.gz ramaskrik-social-701ff00b72b423b77e3d1e09dc7fc1b817b207cb.tar.bz2 ramaskrik-social-701ff00b72b423b77e3d1e09dc7fc1b817b207cb.zip |
Implement adding rooms through the web ui.
Diffstat (limited to 'src/controllers')
-rw-r--r-- | src/controllers/room.rs | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/controllers/room.rs b/src/controllers/room.rs index 8b85344..6458f86 100644 --- a/src/controllers/room.rs +++ b/src/controllers/room.rs @@ -22,12 +22,15 @@ use crate::{ }; use std::result::Result; -use rocket::get; +use rocket::{get, post}; +use rocket::request::{Form, FromForm}; +use rocket::response::Redirect; use rocket_contrib::{ json::Json, templates::Template, }; use serde::Serialize; +use std::collections::HashMap; use std::error::Error; #[derive(Serialize)] @@ -45,3 +48,20 @@ pub fn list_rooms(db: db::Connection) -> Result<Template, Box<dyn Error>> { let ctx = Context { rooms: db.get_rooms()? }; Ok(Template::render("room/list", &ctx)) } + +#[get("/new")] +pub fn new_room() -> Result<Template, Box<dyn Error>> { + let ctx: HashMap<String, String> = HashMap::new(); + Ok(Template::render("room/new", &ctx)) +} + +#[derive(FromForm)] +pub struct NewRoomForm { + name: String, +} + +#[post("/", format = "application/x-www-form-urlencoded", data = "<room>")] +pub fn create_room(db: db::Connection, room: Form<NewRoomForm>) -> Result<Redirect, Box<dyn Error>> { + db.create_room(&room.name)?; + Ok(Redirect::to("/rooms")) +} |