aboutsummaryrefslogtreecommitdiffstats
path: root/src/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'src/controllers')
-rw-r--r--src/controllers/room.rs16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/controllers/room.rs b/src/controllers/room.rs
index 43d3e60..8b85344 100644
--- a/src/controllers/room.rs
+++ b/src/controllers/room.rs
@@ -21,25 +21,27 @@ use crate::{
models,
};
+use std::result::Result;
use rocket::get;
use rocket_contrib::{
json::Json,
templates::Template,
};
use serde::Serialize;
+use std::error::Error;
#[derive(Serialize)]
struct Context {
rooms : Vec<models::Room>,
}
-#[get("/", rank = 1)]
-pub fn list_rooms(db: db::Connection) -> Template {
- let ctx = Context { rooms: db.get_rooms().unwrap() };
- Template::render("room/list", &ctx)
-}
-
-#[get("/", format = "application/json", rank = 2)]
+#[get("/", format = "application/json", rank = 1)]
pub fn get_rooms_json(db: db::Connection) -> Json<Vec<models::Room>> {
Json(db.get_rooms().unwrap())
}
+
+#[get("/", rank = 2)]
+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))
+}