Compare commits

..

5 Commits

Author SHA1 Message Date
1b6aec8d89 Merge pull request 'deletion-event-only-ok-noone-registered' (#513) from deletion-event-only-ok-noone-registered into staging
All checks were successful
CI/CD Pipeline / test (push) Successful in 10m14s
CI/CD Pipeline / deploy-staging (push) Successful in 8m2s
CI/CD Pipeline / deploy-main (push) Has been skipped
Reviewed-on: #513
2024-05-21 18:44:47 +02:00
1bf1cc9c68 inform user in case event can't be deleted
All checks were successful
CI/CD Pipeline / test (push) Successful in 9m50s
CI/CD Pipeline / deploy-staging (push) Has been skipped
CI/CD Pipeline / deploy-main (push) Has been skipped
2024-05-21 18:34:17 +02:00
02e1f77f65 don't allow to delete an event if someone is registered
Some checks failed
CI/CD Pipeline / deploy-staging (push) Blocked by required conditions
CI/CD Pipeline / deploy-main (push) Blocked by required conditions
CI/CD Pipeline / test (push) Has been cancelled
2024-05-21 18:28:56 +02:00
d819462b0d Merge pull request 'log if admin resets the pw for someone' (#512) from log-pw-reset into main
All checks were successful
CI/CD Pipeline / test (push) Successful in 9m1s
CI/CD Pipeline / deploy-staging (push) Has been skipped
CI/CD Pipeline / deploy-main (push) Successful in 7m21s
Reviewed-on: #512
2024-05-21 09:06:46 +02:00
fc49e6c977 Merge pull request 'inform coxes about status of boats' (#510) from notification-on-boatdamages into main
All checks were successful
CI/CD Pipeline / test (push) Successful in 10m0s
CI/CD Pipeline / deploy-staging (push) Has been skipped
CI/CD Pipeline / deploy-main (push) Successful in 7m57s
Reviewed-on: #510
2024-05-20 21:21:56 +02:00
2 changed files with 26 additions and 7 deletions

View File

@ -240,11 +240,29 @@ INNER JOIN trip_details ON planned_event.trip_details_id = trip_details.id",
.unwrap(); //Okay, as planned_event can only be created with proper DB backing
}
pub async fn delete(&self, db: &SqlitePool) {
pub async fn delete(&self, db: &SqlitePool) -> Result<(), String> {
if Registration::all_rower(db, self.trip_details_id)
.await
.len()
> 0
{
return Err(
"Event kann nicht gelöscht werden, weil mind. 1 Ruderer angemeldet ist.".into(),
);
}
if Registration::all_cox(db, self.trip_details_id).await.len() > 0 {
return Err(
"Event kann nicht gelöscht werden, weil mind. 1 Steuerperson angemeldet ist."
.into(),
);
}
sqlx::query!("DELETE FROM planned_event WHERE id = ?", self.id)
.execute(db)
.await
.unwrap(); //Okay, as PlannedEvent can only be created with proper DB backing
Ok(())
}
pub async fn get_ics_feed(db: &SqlitePool) -> String {

View File

@ -78,12 +78,13 @@ async fn update(
#[get("/planned-event/<id>/delete")]
async fn delete(db: &State<SqlitePool>, id: i64, _admin: PlannedEventUser) -> Flash<Redirect> {
match PlannedEvent::find_by_id(db, id).await {
Some(planned_event) => {
planned_event.delete(db).await;
Flash::success(Redirect::to("/planned"), "Event gelöscht")
}
None => Flash::error(Redirect::to("/planned"), "PlannedEvent does not exist"),
let Some(event) = PlannedEvent::find_by_id(db, id).await else {
return Flash::error(Redirect::to("/planned"), "PlannedEvent does not exist");
};
match event.delete(db).await {
Ok(()) => Flash::success(Redirect::to("/planned"), "Event gelöscht"),
Err(e) => Flash::error(Redirect::to("/planned"), e),
}
}