diff --git a/src/tera/log.rs b/src/tera/log.rs index 95a0824..56c5dcb 100644 --- a/src/tera/log.rs +++ b/src/tera/log.rs @@ -1,9 +1,13 @@ use rocket::{ form::Form, - get, post, - request::{FlashMessage, FromRequest, self}, + get, + http::{Cookie, CookieJar}, + post, + request::{self, FlashMessage, FromRequest}, response::{Flash, Redirect}, - routes, Route, State, Request, http::{CookieJar, Cookie}, time::{OffsetDateTime, Duration}, + routes, + time::{Duration, OffsetDateTime}, + Request, Route, State, }; use rocket_dyn_templates::Template; use sqlx::SqlitePool; @@ -62,12 +66,8 @@ async fn index( Template::render("log", context.into_json()) } - #[get("/kiosk/ekrv2019")] -fn new_kiosk( - flash: Option>, - cookies: &CookieJar<'_>, -) -> Redirect { +fn new_kiosk(cookies: &CookieJar<'_>) -> Redirect { let mut cookie = Cookie::new("kiosk", format!("yes")); cookie.set_expires(OffsetDateTime::now_utc() + Duration::weeks(12)); cookies.add_private(cookie); @@ -75,7 +75,11 @@ fn new_kiosk( } #[get("/kiosk")] -async fn kiosk(db: &State, flash: Option>, _kiosk: KioskCookie) -> Template { +async fn kiosk( + db: &State, + flash: Option>, + _kiosk: KioskCookie, +) -> Template { let boats = Boat::all(db).await; let coxes = User::cox(db).await; let users = User::all(db).await; @@ -101,7 +105,7 @@ async fn kiosk(db: &State, flash: Option>, _kiosk: Template::render("kiosk", context.into_json()) } -#[post("/", data = "", rank=2)] +#[post("/", data = "", rank = 2)] async fn create( db: &State, data: Form, @@ -122,10 +126,7 @@ async fn create( } #[post("/", data = "")] -async fn create_kiosk( - db: &State, - data: Form, -) -> Flash { +async fn create_kiosk(db: &State, data: Form) -> Flash { match Logbook::create( db, data.into_inner() @@ -140,7 +141,6 @@ async fn create_kiosk( } } - #[post("/", data = "")] async fn home_kiosk( db: &State, @@ -155,7 +155,16 @@ async fn home_kiosk( ) }; - match logbook.home(db, &User::find_by_id(db, logbook.shipmaster as i32).await.unwrap(), data.into_inner()).await { + match logbook + .home( + db, + &User::find_by_id(db, logbook.shipmaster as i32) + .await + .unwrap(), + data.into_inner(), + ) + .await + { Ok(_) => Flash::success(Redirect::to("/log"), "Successfully updated log"), Err(_) => Flash::error( Redirect::to("/log"), @@ -164,8 +173,7 @@ async fn home_kiosk( } } - -#[post("/", data = "", rank=2)] +#[post("/", data = "", rank = 2)] async fn home( db: &State, data: Form, @@ -190,7 +198,15 @@ async fn home( } pub fn routes() -> Vec { - routes![index, create, create_kiosk, home, kiosk, home_kiosk, new_kiosk] + routes![ + index, + create, + create_kiosk, + home, + kiosk, + home_kiosk, + new_kiosk + ] } #[cfg(test)]