aboutsummaryrefslogtreecommitdiffstats
path: root/src/controllers
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2020-08-22 19:09:13 +0200
committerHarald Eilertsen <haraldei@anduin.net>2020-08-22 19:09:13 +0200
commit86178bb3a5ad131766a57cdcac9f22fed3c55f8a (patch)
treed4f79f7ac8d56e88432b138265d816356131214f /src/controllers
parent3267754478ea1b83c3da653c4a5f9706c9fdce05 (diff)
downloadramaskrik-social-86178bb3a5ad131766a57cdcac9f22fed3c55f8a.tar.gz
ramaskrik-social-86178bb3a5ad131766a57cdcac9f22fed3c55f8a.tar.bz2
ramaskrik-social-86178bb3a5ad131766a57cdcac9f22fed3c55f8a.zip
Swap rank on plain and json response for room list.
Note to self: More explicit should have lower rank (higher precedence.)
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))
+}