implement is_locked for trip_details

This commit is contained in:
2023-08-09 11:54:18 +02:00
parent 21c5609b31
commit bd4ee5954c
9 changed files with 150 additions and 47 deletions

View File

@ -14,6 +14,10 @@ impl UserTrip {
return Err(UserTripError::EventAlreadyFull);
}
if trip_details.is_locked {
return Err(UserTripError::DetailsLocked);
}
if user.is_guest && !trip_details.allow_guests {
return Err(UserTripError::GuestNotAllowedForThisEvent);
}
@ -68,8 +72,15 @@ impl UserTrip {
}
}
pub async fn delete(db: &SqlitePool, user: &User, trip_details: &TripDetails) {
//TODO: Check if > 2 hrs to event
pub async fn delete(
db: &SqlitePool,
user: &User,
trip_details: &TripDetails,
) -> Result<(), UserTripDeleteError> {
if trip_details.is_locked {
return Err(UserTripDeleteError::DetailsLocked);
}
let _ = sqlx::query!(
"DELETE FROM user_trip WHERE user_id = ? AND trip_details_id = ?",
user.id,
@ -77,7 +88,9 @@ impl UserTrip {
)
.execute(db)
.await
.is_ok();
.unwrap();
Ok(())
}
}
@ -86,10 +99,16 @@ pub enum UserTripError {
AlreadyRegistered,
AlreadyRegisteredAsCox,
EventAlreadyFull,
DetailsLocked,
CantRegisterAtOwnEvent,
GuestNotAllowedForThisEvent,
}
#[derive(Debug, PartialEq)]
pub enum UserTripDeleteError {
DetailsLocked,
}
#[cfg(test)]
mod test {
use crate::{