clean code with clippy

This commit is contained in:
philipp 2023-04-26 12:52:19 +02:00
parent a49de71a5d
commit 9236113507
3 changed files with 6 additions and 12 deletions

View File

@ -131,11 +131,8 @@ FROM user_trip WHERE trip_details_id = (SELECT trip_details_id FROM trip WHERE i
.fetch_one(db) .fetch_one(db)
.await .await
.unwrap(); //TODO: fixme .unwrap(); //TODO: fixme
let trip_details_id = match trip_details.id { let Some(trip_details_id) = trip_details.id else {
Some(id) => id,
None => {
return Err(TripUpdateError::TripDoesNotExist); return Err(TripUpdateError::TripDoesNotExist);
}
}; };
sqlx::query!( sqlx::query!(
@ -152,14 +149,14 @@ FROM user_trip WHERE trip_details_id = (SELECT trip_details_id FROM trip WHERE i
} }
pub async fn delete_by_planned_event_id(db: &SqlitePool, user_id: i64, planned_event_id: i64) { pub async fn delete_by_planned_event_id(db: &SqlitePool, user_id: i64, planned_event_id: i64) {
let _ = sqlx::query!( sqlx::query!(
"DELETE FROM trip WHERE cox_id = ? AND planned_event_id = ?", "DELETE FROM trip WHERE cox_id = ? AND planned_event_id = ?",
user_id, user_id,
planned_event_id planned_event_id
) )
.execute(db) .execute(db)
.await .await
.is_ok(); .unwrap(); //TODO: fixme
} }
pub(crate) async fn delete( pub(crate) async fn delete(

View File

@ -99,11 +99,8 @@ ORDER BY name
} }
pub async fn login(db: &SqlitePool, name: String, pw: String) -> Result<Self, LoginError> { pub async fn login(db: &SqlitePool, name: String, pw: String) -> Result<Self, LoginError> {
let user = match User::find_by_name(db, name).await { let Some(user) = User::find_by_name(db, name).await else {
Some(user) => user,
None => {
return Err(LoginError::InvalidAuthenticationCombo); // Username not found return Err(LoginError::InvalidAuthenticationCombo); // Username not found
}
}; };
match user.pw.clone() { match user.pw.clone() {

View File

@ -10,7 +10,7 @@ impl UserTrip {
user_id: i64, user_id: i64,
trip_details_id: i64, trip_details_id: i64,
) -> Result<(), UserTripError> { ) -> Result<(), UserTripError> {
let trip_details = TripDetails::find_by_id(&db, trip_details_id) let trip_details = TripDetails::find_by_id(db, trip_details_id)
.await .await
.ok_or(UserTripError::TripDetailsNotFound)?; .ok_or(UserTripError::TripDetailsNotFound)?;