add rss feed with common actions

This commit is contained in:
2023-04-18 12:10:11 +02:00
parent b50d546a5c
commit a3ac83228c
8 changed files with 138 additions and 4 deletions

View File

@ -11,6 +11,7 @@ use rocket_dyn_templates::{tera::Context, Template};
use sqlx::SqlitePool;
use crate::model::{
log::Log,
user::User,
usertrip::{UserTrip, UserTripError},
Day,
@ -51,7 +52,17 @@ async fn index(db: &State<SqlitePool>, user: User, flash: Option<FlashMessage<'_
#[get("/join/<trip_details_id>")]
async fn join(db: &State<SqlitePool>, trip_details_id: i64, user: User) -> Flash<Redirect> {
match UserTrip::create(db, user.id, trip_details_id).await {
Ok(_) => Flash::success(Redirect::to("/"), "Erfolgreich angemeldet!"),
Ok(_) => {
Log::create(
db,
format!(
"User {} registered for trip_details.id={}",
user.name, trip_details_id
),
)
.await;
Flash::success(Redirect::to("/"), "Erfolgreich angemeldet!")
}
Err(UserTripError::EventAlreadyFull) => {
Flash::error(Redirect::to("/"), "Event bereits ausgebucht!")
}
@ -68,6 +79,15 @@ async fn join(db: &State<SqlitePool>, trip_details_id: i64, user: User) -> Flash
async fn remove(db: &State<SqlitePool>, trip_details_id: i64, user: User) -> Flash<Redirect> {
UserTrip::delete(db, user.id, trip_details_id).await;
Log::create(
db,
format!(
"User {} unregistered for trip_details.id={}",
user.name, trip_details_id
),
)
.await;
Flash::success(Redirect::to("/"), "Erfolgreich abgemeldet!")
}