reduce amount of magic values, goal is to have specific states -> e.g. cancelled
This commit is contained in:
@@ -46,6 +46,12 @@ pub struct TripUpdate<'a> {
|
||||
pub is_locked: bool,
|
||||
}
|
||||
|
||||
impl<'a> TripUpdate<'a> {
|
||||
fn cancelled(&self) -> bool {
|
||||
self.max_people == -1
|
||||
}
|
||||
}
|
||||
|
||||
impl TripWithUserAndType {
|
||||
pub async fn from(db: &SqlitePool, trip: Trip) -> Self {
|
||||
let mut trip_type = None;
|
||||
@@ -245,7 +251,7 @@ WHERE trip.id=?
|
||||
return Err(CoxHelpError::DetailsLocked);
|
||||
}
|
||||
|
||||
if event.max_people == 0 {
|
||||
if event.is_cancelled() {
|
||||
return Err(CoxHelpError::CanceledEvent);
|
||||
}
|
||||
|
||||
@@ -309,9 +315,9 @@ WHERE day=?
|
||||
};
|
||||
|
||||
let tripdetails = TripDetails::find_by_id(db, trip_details_id).await.unwrap();
|
||||
let was_already_cancelled = tripdetails.max_people == 0;
|
||||
let was_already_cancelled = tripdetails.cancelled();
|
||||
|
||||
let is_locked = if update.max_people == 0 {
|
||||
let is_locked = if update.cancelled() {
|
||||
false
|
||||
} else {
|
||||
update.is_locked
|
||||
@@ -329,7 +335,7 @@ WHERE day=?
|
||||
.await
|
||||
.unwrap(); //Okay, as trip_details can only be created with proper DB backing
|
||||
|
||||
if update.max_people == 0 && !was_already_cancelled {
|
||||
if update.cancelled() && !was_already_cancelled {
|
||||
let rowers = TripWithUserAndType::from(db, update.trip.clone())
|
||||
.await
|
||||
.rower;
|
||||
@@ -368,7 +374,7 @@ WHERE day=?
|
||||
.await;
|
||||
}
|
||||
|
||||
if update.max_people > 0 && was_already_cancelled {
|
||||
if !update.cancelled() && was_already_cancelled {
|
||||
Notification::delete_by_action(
|
||||
db,
|
||||
&format!("remove_user_trip_with_trip_details_id:{}", trip_details_id),
|
||||
@@ -463,7 +469,7 @@ WHERE day=?
|
||||
}
|
||||
|
||||
fn is_cancelled(&self) -> bool {
|
||||
self.max_people == 0
|
||||
self.max_people == -1
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user