diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/controllers/home_controller.rs | 8 | ||||
-rw-r--r-- | src/controllers/login_controller.rs | 4 | ||||
-rw-r--r-- | src/controllers/posts_controller.rs | 12 | ||||
-rw-r--r-- | src/controllers/users_controller.rs | 5 | ||||
-rw-r--r-- | src/main.rs | 35 |
5 files changed, 39 insertions, 25 deletions
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<Vec<models::Post>> { fn public_file(file: PathBuf) -> Option<rocket::response::NamedFile> { rocket::response::NamedFile::open(PathBuf::from("public/").join(file)).ok() } + +pub fn routes() -> Vec<rocket::Route> { + 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<LoginForm>, conn: utils::DbConn) -> Flash<Redirect> { Flash::error(Redirect::to("/login"), "Invalid email or passoword!") } + +pub fn routes() -> Vec<rocket::Route> { + 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<Redirect> { ::models::Post::delete(id, conn); Flash::success(Redirect::to("/"), "Post deleted!") } + +pub fn routes() -> Vec<rocket::Route> { + 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<Redirect> Err(_) => Flash::error(Redirect::to("/"), "Could not create user!") } } + +pub fn routes() -> Vec<rocket::Route> { + routes![new, create] +} diff --git a/src/main.rs b/src/main.rs index 6fa552f..4515a2d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,36 +16,21 @@ extern crate rocket_contrib; mod models; mod schema; mod controllers; -use controllers::home_controller; -use controllers::{login_controller, posts_controller, users_controller}; +use controllers::{ + home_controller, + login_controller, + posts_controller, + users_controller +}; fn main() { if let Ok(dburl) = dotenv::var("DATABASE_URL") { rocket::ignite() .manage(utils::init_db_pool(&dburl)) - .mount("/", - routes![ - home_controller::index, - home_controller::index_json, - home_controller::public_file]) - .mount("/posts", - routes![ - posts_controller::new, - posts_controller::create, - posts_controller::show, - posts_controller::edit, - posts_controller::update, - posts_controller::delete]) - .mount("/users", - routes![ - users_controller::new, - users_controller::create, - ]) - .mount("/login", - routes![ - login_controller::new, - login_controller::create, - ]) + .mount("/", home_controller::routes()) + .mount("/posts", posts_controller::routes()) + .mount("/users", users_controller::routes()) + .mount("/login", login_controller::routes()) .launch(); } else { |