allow users to delete trips
This commit is contained in:
@ -68,6 +68,11 @@ pub enum LogbookUpdateError {
|
||||
ArrivalNotAfterDeparture,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum LogbookDeleteError {
|
||||
NotYourEntry,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum LogbookCreateError {
|
||||
BoatAlreadyOnWater,
|
||||
@ -327,11 +332,15 @@ ORDER BY departure DESC
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn delete(&self, db: &SqlitePool) {
|
||||
sqlx::query!("DELETE FROM logbook WHERE id=?", self.id)
|
||||
.execute(db)
|
||||
.await
|
||||
.unwrap(); //Okay, because we can only create a Logbook of a valid id
|
||||
pub async fn delete(&self, db: &SqlitePool, user: &User) -> Result<(), LogbookDeleteError> {
|
||||
if user.is_admin || user.id == self.shipmaster {
|
||||
sqlx::query!("DELETE FROM logbook WHERE id=?", self.id)
|
||||
.execute(db)
|
||||
.await
|
||||
.unwrap(); //Okay, because we can only create a Logbook of a valid id
|
||||
return Ok(());
|
||||
}
|
||||
Err(LogbookDeleteError::NotYourEntry)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user