From bae288cb431aab7c61731527676376b268aa9b84 Mon Sep 17 00:00:00 2001 From: philipp Date: Tue, 30 May 2023 14:47:44 +0200 Subject: [PATCH] clean code with clippy --- src/model/trip.rs | 6 +++--- src/rest/mod.rs | 15 +++++---------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/model/trip.rs b/src/model/trip.rs index 815e300..339798a 100644 --- a/src/model/trip.rs +++ b/src/model/trip.rs @@ -140,7 +140,7 @@ FROM user_trip WHERE trip_details_id = (SELECT trip_details_id FROM trip WHERE i notes: Option<&str>, trip_type: Option, //TODO: Move to `TripType` ) -> Result<(), TripUpdateError> { - if !trip.is_trip_from_user(cox.id).await { + if !trip.is_trip_from_user(cox.id) { return Err(TripUpdateError::NotYourTrip); } @@ -194,7 +194,7 @@ FROM user_trip WHERE trip_details_id = (SELECT trip_details_id FROM trip WHERE i return Err(TripDeleteError::SomebodyAlreadyRegistered); } - if !self.is_trip_from_user(user.id).await { + if !self.is_trip_from_user(user.id) { return Err(TripDeleteError::NotYourTrip); } @@ -210,7 +210,7 @@ FROM user_trip WHERE trip_details_id = (SELECT trip_details_id FROM trip WHERE i Ok(()) } - async fn is_trip_from_user(&self, user_id: i64) -> bool { + fn is_trip_from_user(&self, user_id: i64) -> bool { self.cox_id == user_id } } diff --git a/src/rest/mod.rs b/src/rest/mod.rs index 3fca91f..3e8850c 100644 --- a/src/rest/mod.rs +++ b/src/rest/mod.rs @@ -73,10 +73,8 @@ async fn index(db: &State, user: User, flash: Option")] async fn join(db: &State, trip_details_id: i64, user: User) -> Flash { - let trip_details = match TripDetails::find_by_id(db, trip_details_id).await { - Some(trip_details) => trip_details, - None => return Flash::error(Redirect::to("/"), "Trip_details do not exist."), - }; + let Some(trip_details) = TripDetails::find_by_id(db, trip_details_id).await else { return Flash::error(Redirect::to("/"), "Trip_details do not exist.") }; + match UserTrip::create(db, &user, &trip_details).await { Ok(_) => { Log::create( @@ -111,12 +109,9 @@ async fn join(db: &State, trip_details_id: i64, user: User) -> Flash #[get("/remove/")] async fn remove(db: &State, trip_details_id: i64, user: User) -> Flash { - let trip_details = match TripDetails::find_by_id(db, trip_details_id).await { - Some(trip_details) => trip_details, - None => { - return Flash::error(Redirect::to("/"), "TripDetailsId does not exist"); - } - }; + let Some(trip_details) = TripDetails::find_by_id(db, trip_details_id).await else { + return Flash::error(Redirect::to("/"), "TripDetailsId does not exist"); + }; UserTrip::delete(db, &user, &trip_details).await;