clean code with clippy
This commit is contained in:
parent
9c30cda326
commit
bae288cb43
@ -140,7 +140,7 @@ FROM user_trip WHERE trip_details_id = (SELECT trip_details_id FROM trip WHERE i
|
|||||||
notes: Option<&str>,
|
notes: Option<&str>,
|
||||||
trip_type: Option<i64>, //TODO: Move to `TripType`
|
trip_type: Option<i64>, //TODO: Move to `TripType`
|
||||||
) -> Result<(), TripUpdateError> {
|
) -> Result<(), TripUpdateError> {
|
||||||
if !trip.is_trip_from_user(cox.id).await {
|
if !trip.is_trip_from_user(cox.id) {
|
||||||
return Err(TripUpdateError::NotYourTrip);
|
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);
|
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);
|
return Err(TripDeleteError::NotYourTrip);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,7 +210,7 @@ FROM user_trip WHERE trip_details_id = (SELECT trip_details_id FROM trip WHERE i
|
|||||||
Ok(())
|
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
|
self.cox_id == user_id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,10 +73,8 @@ async fn index(db: &State<SqlitePool>, user: User, flash: Option<FlashMessage<'_
|
|||||||
|
|
||||||
#[get("/join/<trip_details_id>")]
|
#[get("/join/<trip_details_id>")]
|
||||||
async fn join(db: &State<SqlitePool>, trip_details_id: i64, user: User) -> Flash<Redirect> {
|
async fn join(db: &State<SqlitePool>, trip_details_id: i64, user: User) -> Flash<Redirect> {
|
||||||
let trip_details = match TripDetails::find_by_id(db, trip_details_id).await {
|
let Some(trip_details) = TripDetails::find_by_id(db, trip_details_id).await else { return Flash::error(Redirect::to("/"), "Trip_details do not exist.") };
|
||||||
Some(trip_details) => trip_details,
|
|
||||||
None => return Flash::error(Redirect::to("/"), "Trip_details do not exist."),
|
|
||||||
};
|
|
||||||
match UserTrip::create(db, &user, &trip_details).await {
|
match UserTrip::create(db, &user, &trip_details).await {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
Log::create(
|
Log::create(
|
||||||
@ -111,12 +109,9 @@ async fn join(db: &State<SqlitePool>, trip_details_id: i64, user: User) -> Flash
|
|||||||
|
|
||||||
#[get("/remove/<trip_details_id>")]
|
#[get("/remove/<trip_details_id>")]
|
||||||
async fn remove(db: &State<SqlitePool>, trip_details_id: i64, user: User) -> Flash<Redirect> {
|
async fn remove(db: &State<SqlitePool>, trip_details_id: i64, user: User) -> Flash<Redirect> {
|
||||||
let trip_details = match TripDetails::find_by_id(db, trip_details_id).await {
|
let Some(trip_details) = TripDetails::find_by_id(db, trip_details_id).await else {
|
||||||
Some(trip_details) => trip_details,
|
return Flash::error(Redirect::to("/"), "TripDetailsId does not exist");
|
||||||
None => {
|
};
|
||||||
return Flash::error(Redirect::to("/"), "TripDetailsId does not exist");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
UserTrip::delete(db, &user, &trip_details).await;
|
UserTrip::delete(db, &user, &trip_details).await;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user