From 17d1ee35669044487f50445e1ac1a0301c935433 Mon Sep 17 00:00:00 2001 From: philipp Date: Tue, 30 Apr 2024 21:35:14 +0200 Subject: [PATCH] clippy :-) --- src/model/boat.rs | 10 ++++------ src/model/boatreservation.rs | 2 +- src/model/logbook.rs | 8 ++++---- src/model/user.rs | 8 +------- src/tera/admin/schnupper.rs | 22 +--------------------- src/tera/boatreservation.rs | 2 +- src/tera/log.rs | 2 +- src/tera/mod.rs | 6 ++---- 8 files changed, 15 insertions(+), 45 deletions(-) diff --git a/src/model/boat.rs b/src/model/boat.rs index cb13121..dd6d3e6 100644 --- a/src/model/boat.rs +++ b/src/model/boat.rs @@ -181,13 +181,11 @@ AND date('now') BETWEEN start_date AND end_date;", damage = BoatDamage::Locked; } let cat = if boat.external { - format!("Vereinsfremde Boote") + "Vereinsfremde Boote".to_string() + } else if boat.default_shipmaster_only_steering { + format!("{}+", boat.amount_seats - 1) } else { - if boat.default_shipmaster_only_steering { - format!("{}+", boat.amount_seats - 1) - } else { - format!("{}x", boat.amount_seats) - } + format!("{}x", boat.amount_seats) }; res.push(BoatWithDetails { diff --git a/src/model/boatreservation.rs b/src/model/boatreservation.rs index 804d384..d3d56f0 100644 --- a/src/model/boatreservation.rs +++ b/src/model/boatreservation.rs @@ -114,7 +114,7 @@ WHERE end_date >= CURRENT_DATE ORDER BY end_date grouped_reservations .entry(key) - .or_insert_with(Vec::new) + .or_default() .push(reservation); } diff --git a/src/model/logbook.rs b/src/model/logbook.rs index 388393f..66b7a4e 100644 --- a/src/model/logbook.rs +++ b/src/model/logbook.rs @@ -303,10 +303,10 @@ ORDER BY departure DESC return Err(LogbookCreateError::BoatNotFound); }; - if log.shipmaster_only_steering != boat.default_shipmaster_only_steering { - if !boat.convert_handoperated_possible { - return Err(LogbookCreateError::CantChangeHandoperatableStatusForThisBoat); - } + if log.shipmaster_only_steering != boat.default_shipmaster_only_steering + && !boat.convert_handoperated_possible + { + return Err(LogbookCreateError::CantChangeHandoperatableStatusForThisBoat); } if boat.amount_seats == 1 && log.rowers.is_empty() { diff --git a/src/model/user.rs b/src/model/user.rs index 07c9f93..bb540aa 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -26,7 +26,7 @@ const REGULAR: i32 = 22000; const UNTERSTUETZEND: i32 = 2500; const FOERDERND: i32 = 8500; -#[derive(FromRow, Serialize, Deserialize, Clone, Debug, Eq, Hash)] +#[derive(FromRow, Serialize, Deserialize, Clone, Debug, Eq, Hash, PartialEq)] pub struct User { pub id: i64, pub name: String, @@ -82,12 +82,6 @@ impl UserWithWaterStatus { } } -impl PartialEq for User { - fn eq(&self, other: &Self) -> bool { - self.id == other.id - } -} - #[derive(Debug)] pub enum LoginError { InvalidAuthenticationCombo, diff --git a/src/tera/admin/schnupper.rs b/src/tera/admin/schnupper.rs index f08abb3..d7a704a 100644 --- a/src/tera/admin/schnupper.rs +++ b/src/tera/admin/schnupper.rs @@ -3,30 +3,10 @@ use crate::model::{ user::{SchnupperBetreuerUser, User, UserWithRolesAndNotificationCount}, }; use futures::future::join_all; -use rocket::{ - get, - http::Status, - request::{FlashMessage, FromRequest, Outcome}, - routes, Request, Route, State, -}; +use rocket::{get, request::FlashMessage, routes, Route, State}; use rocket_dyn_templates::{tera::Context, Template}; use sqlx::SqlitePool; -// Custom request guard to extract the Referer header -struct Referer(String); - -#[rocket::async_trait] -impl<'r> FromRequest<'r> for Referer { - type Error = (); - - async fn from_request(request: &'r Request<'_>) -> Outcome { - match request.headers().get_one("Referer") { - Some(referer) => Outcome::Success(Referer(referer.to_string())), - None => Outcome::Error((Status::BadRequest, ())), - } - } -} - #[get("/schnupper")] async fn index( db: &State, diff --git a/src/tera/boatreservation.rs b/src/tera/boatreservation.rs index 608eaae..3c406bc 100644 --- a/src/tera/boatreservation.rs +++ b/src/tera/boatreservation.rs @@ -166,7 +166,7 @@ async fn update( if user.id != reservation.user_id_applicant && !user.has_role(db, "admin").await { return Flash::error( Redirect::to("/boatreservation"), - format!("Not allowed to update reservation (only admins + creator do so)."), + "Not allowed to update reservation (only admins + creator do so).".to_string(), ); } diff --git a/src/tera/log.rs b/src/tera/log.rs index 0cdca4a..e6caef7 100644 --- a/src/tera/log.rs +++ b/src/tera/log.rs @@ -250,7 +250,7 @@ async fn create_kiosk( } else if let Some(shipmaster) = data.shipmaster { User::find_by_id(db, shipmaster as i32).await.unwrap() } else { - let Some(rower) = data.rowers.get(0) else { + let Some(rower) = data.rowers.first() else { return Flash::error( Redirect::to("/log"), "Ausfahrt ohne Benutzer kann nicht angelegt werden.", diff --git a/src/tera/mod.rs b/src/tera/mod.rs index 33bbf53..7fc6ead 100644 --- a/src/tera/mod.rs +++ b/src/tera/mod.rs @@ -109,9 +109,7 @@ fn forbidden_error() -> Flash { Flash::error(Redirect::to("/"), "Keine Berechtigung für diese Aktion. Wenn du der Meinung bist, dass du das machen darfst, melde dich bitte bei it@rudernlinz.at.") } -struct Usage { - data: Vec, -} +struct Usage {} #[rocket::async_trait] impl Fairing for Usage { @@ -196,7 +194,7 @@ pub fn config(rocket: Rocket) -> Rocket { .register("/", catchers![unauthorized_error, forbidden_error]) .attach(Template::fairing()) .attach(AdHoc::config::()) - .attach(Usage { data: Vec::new() }) + .attach(Usage {}) } #[cfg(test)]