From 6e5801a75399f7b8bc7adb1b19bc2d26e169f970 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Tue, 31 Jul 2018 15:14:44 +0200 Subject: Move routing details into controllers. --- src/controllers/home_controller.rs | 8 ++++++++ src/controllers/login_controller.rs | 4 ++++ src/controllers/posts_controller.rs | 12 ++++++++++++ src/controllers/users_controller.rs | 5 +++++ 4 files changed, 29 insertions(+) (limited to 'src/controllers') diff --git a/src/controllers/home_controller.rs b/src/controllers/home_controller.rs index 2f657c3..bef47de 100644 --- a/src/controllers/home_controller.rs +++ b/src/controllers/home_controller.rs @@ -37,3 +37,11 @@ fn index_json(conn: utils::DbConn) -> Json> { fn public_file(file: PathBuf) -> Option { rocket::response::NamedFile::open(PathBuf::from("public/").join(file)).ok() } + +pub fn routes() -> Vec { + routes![ + index, + index_json, + public_file + ] +} diff --git a/src/controllers/login_controller.rs b/src/controllers/login_controller.rs index 35841b3..800a6b2 100644 --- a/src/controllers/login_controller.rs +++ b/src/controllers/login_controller.rs @@ -36,3 +36,7 @@ pub fn create(login: Form, conn: utils::DbConn) -> Flash { Flash::error(Redirect::to("/login"), "Invalid email or passoword!") } + +pub fn routes() -> Vec { + routes![new, create] +} diff --git a/src/controllers/posts_controller.rs b/src/controllers/posts_controller.rs index aca9d13..f10f312 100644 --- a/src/controllers/posts_controller.rs +++ b/src/controllers/posts_controller.rs @@ -1,4 +1,5 @@ use comrak::{markdown_to_html, ComrakOptions}; +use rocket; use rocket::request::Form; use rocket::response::{Flash, Redirect}; use utils; @@ -83,3 +84,14 @@ fn delete(id: i32, conn: utils::DbConn) -> Flash { ::models::Post::delete(id, conn); Flash::success(Redirect::to("/"), "Post deleted!") } + +pub fn routes() -> Vec { + routes![ + new, + create, + show, + edit, + update, + delete + ] +} diff --git a/src/controllers/users_controller.rs b/src/controllers/users_controller.rs index 8dcd4c0..9708a1b 100644 --- a/src/controllers/users_controller.rs +++ b/src/controllers/users_controller.rs @@ -1,3 +1,4 @@ +use rocket; use rocket::request::Form; use rocket::response::{Flash, Redirect}; use utils; @@ -38,3 +39,7 @@ fn create(user: Form<::models::NewUser>, conn: utils::DbConn) -> Flash Err(_) => Flash::error(Redirect::to("/"), "Could not create user!") } } + +pub fn routes() -> Vec { + routes![new, create] +} -- cgit v1.2.3