From daf8afd7318950e378ea3253c467c91f4ebcd7b7 Mon Sep 17 00:00:00 2001 From: philipp Date: Mon, 24 Apr 2023 14:34:06 +0200 Subject: [PATCH] clean code with clippy --- src/model/trip.rs | 2 +- src/model/user.rs | 32 ++++++++++++++------------------ 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/model/trip.rs b/src/model/trip.rs index efcad68..5df6f0f 100644 --- a/src/model/trip.rs +++ b/src/model/trip.rs @@ -168,7 +168,7 @@ FROM user_trip WHERE trip_details_id = (SELECT trip_details_id FROM trip WHERE i trip_id: i64, ) -> Result<(), TripDeleteError> { let registered_rower = Self::get_all_rower_for_id(db, trip_id).await; - if registered_rower.len() > 0 { + if registered_rower.is_empty() { return Err(TripDeleteError::SomebodyAlreadyRegistered); } diff --git a/src/model/user.rs b/src/model/user.rs index aab0331..5df259d 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -55,37 +55,33 @@ impl User { } pub async fn find_by_id(db: &SqlitePool, id: i32) -> Option { - Some( - sqlx::query_as!( - User, - " + sqlx::query_as!( + User, + " SELECT id, name, pw, is_cox, is_admin, is_guest FROM user WHERE id like ? ", - id - ) - .fetch_one(db) - .await - .ok()?, + id ) + .fetch_one(db) + .await + .ok() } async fn find_by_name(db: &SqlitePool, name: String) -> Option { - Some( - sqlx::query_as!( - User, - " + sqlx::query_as!( + User, + " SELECT id, name, pw, is_cox, is_admin, is_guest FROM user WHERE name like ? ", - name - ) - .fetch_one(db) - .await - .ok()?, + name ) + .fetch_one(db) + .await + .ok() } fn get_hashed_pw(pw: &str) -> String {