Previously, we only needed to get the last week number from the index, to properly redirect to it. However, we will need it in the future in other places. Implement a function that centralizes this database operation.
39 lines
861 B
Rust
39 lines
861 B
Rust
#[macro_use] extern crate rocket;
|
|
|
|
use rocket::fs::{FileServer, relative};
|
|
use rocket::response::Redirect;
|
|
|
|
use rocket_dyn_templates::Template;
|
|
|
|
use rocket_db_pools::Connection;
|
|
|
|
mod auth;
|
|
|
|
mod truth;
|
|
mod vote;
|
|
mod week;
|
|
|
|
|
|
mod database;
|
|
mod database_records;
|
|
use database::Db;
|
|
|
|
#[get("/")]
|
|
async fn index(mut db: Connection<Db>) -> Redirect {
|
|
let current_week: u8 = week::get_last_week(&mut db).await;
|
|
|
|
Redirect::to(uri!(week::week(week_number = if current_week == 0 {1} else {current_week})))
|
|
}
|
|
|
|
#[launch]
|
|
fn rocket() -> _ {
|
|
rocket::build()
|
|
.mount("/static/", FileServer::from(relative!("static_files")))
|
|
.attach(auth::stage())
|
|
.attach(week::stage())
|
|
.attach(truth::stage())
|
|
.attach(vote::stage())
|
|
.mount("/", routes![index])
|
|
.attach(database::stage())
|
|
.attach(Template::fairing())
|
|
}
|