#![recursion_limit = "256"] #![feature(proc_macro_hygiene, decl_macro)] #[macro_use] extern crate diesel; #[macro_use] extern crate diesel_migrations; use rocket::fairing::AdHoc; use rocket::{catchers, routes, Rocket}; use rocket_contrib::database; use rocket_contrib::serve::StaticFiles; #[macro_use] pub mod helpers; pub mod catchers; pub mod handlers; // This macro from `diesel_migrations` defines an `embedded_migrations` module containing a // function named `run`. This allows the example to be run and tested without any outside setup of // the database. embed_migrations!(); #[database("stoptime_db")] pub struct DbConn(diesel::SqliteConnection); /// Runs the database migrations. fn run_db_migrations(rocket: Rocket) -> Result { let conn = DbConn::get_one(&rocket).expect("Failed to get a database connection"); match embedded_migrations::run(&*conn) { Ok(()) => Ok(rocket), Err(e) => { eprintln!("Failed to run database migrations: {:?}", e); Err(rocket) } } } /// Sets up the Rocket application. fn rocket() -> Rocket { let static_dir = concat!(env!("CARGO_MANIFEST_DIR"), "/static"); let static_files = StaticFiles::from(static_dir); rocket::ignite() .attach(DbConn::fairing()) .attach(AdHoc::on_attach("Database Migrations", run_db_migrations)) .mount("/", routes![handlers::index]) .mount( "/company", routes![handlers::company::index, handlers::company::create], ) .mount( "/customers", routes![ handlers::customers::index, handlers::customers::create, handlers::customers::new, handlers::customers::show, handlers::customers::update, handlers::customers::destroy, handlers::customers::invoices::create, handlers::customers::invoices::new, handlers::customers::invoices::show, handlers::customers::invoices::update, handlers::customers::tasks::create, handlers::customers::tasks::new, handlers::customers::tasks::show, handlers::customers::tasks::update, handlers::customers::tasks::destroy, ], ) .mount("/invoices", routes![handlers::invoices::index]) .mount("/static", static_files) .mount( "/timeline", routes![ handlers::timeline::index, handlers::timeline::create, handlers::timeline::new, handlers::timeline::show, handlers::timeline::update, handlers::timeline::destroy, ], ) .register(catchers![ catchers::not_found, catchers::unprocessable_entity ]) } /// Runs the Rocket application. fn main() { rocket().launch(); }