Compare commits
No commits in common. "c4ca148b54563ccb7c5b3946a3677570e7e5583b" and "122e5daab28fdd8aff8359da3f43867e99818538" have entirely different histories.
c4ca148b54
...
122e5daab2
@ -5,7 +5,7 @@ use regex::Regex;
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::{FromRow, Sqlite, SqlitePool, Transaction};
|
use sqlx::{FromRow, Sqlite, SqlitePool, Transaction};
|
||||||
|
|
||||||
use super::{role::Role, user::User, usertrip::UserTrip};
|
use super::{role::Role, user::User};
|
||||||
|
|
||||||
#[derive(FromRow, Debug, Serialize, Deserialize, Clone)]
|
#[derive(FromRow, Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct Notification {
|
pub struct Notification {
|
||||||
@ -140,13 +140,15 @@ ORDER BY read_at DESC, created_at DESC;
|
|||||||
let re = Regex::new(r"^remove_user_trip_with_trip_details_id:(\d+)$").unwrap();
|
let re = Regex::new(r"^remove_user_trip_with_trip_details_id:(\d+)$").unwrap();
|
||||||
if let Some(caps) = re.captures(action) {
|
if let Some(caps) = re.captures(action) {
|
||||||
if let Some(matched) = caps.get(1) {
|
if let Some(matched) = caps.get(1) {
|
||||||
if let Ok(number) = matched.as_str().parse::<i64>() {
|
if let Ok(number) = matched.as_str().parse::<i32>() {
|
||||||
if let Some(usertrip) =
|
let _ = sqlx::query!(
|
||||||
UserTrip::find_by_userid_and_trip_detail_id(db, self.user_id, number)
|
"DELETE FROM user_trip WHERE user_id = ? AND trip_details_id = ?",
|
||||||
|
self.user_id,
|
||||||
|
number
|
||||||
|
)
|
||||||
|
.execute(db)
|
||||||
.await
|
.await
|
||||||
{
|
.unwrap();
|
||||||
let _ = usertrip.self_delete(db).await;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -215,18 +215,12 @@ WHERE day=?
|
|||||||
let tripdetails = TripDetails::find_by_id(db, trip_details_id).await.unwrap();
|
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.max_people == 0;
|
||||||
|
|
||||||
let is_locked = if update.max_people == 0 {
|
|
||||||
false
|
|
||||||
} else {
|
|
||||||
update.is_locked
|
|
||||||
};
|
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"UPDATE trip_details SET max_people = ?, notes = ?, trip_type_id = ?, is_locked = ? WHERE id = ?",
|
"UPDATE trip_details SET max_people = ?, notes = ?, trip_type_id = ?, is_locked = ? WHERE id = ?",
|
||||||
update.max_people,
|
update.max_people,
|
||||||
update.notes,
|
update.notes,
|
||||||
update.trip_type,
|
update.trip_type,
|
||||||
is_locked,
|
update.is_locked,
|
||||||
trip_details_id
|
trip_details_id
|
||||||
)
|
)
|
||||||
.execute(db)
|
.execute(db)
|
||||||
@ -248,7 +242,7 @@ WHERE day=?
|
|||||||
db,
|
db,
|
||||||
&user,
|
&user,
|
||||||
&format!(
|
&format!(
|
||||||
"Die Ausfahrt von {} am {} um {} wurde abgesagt. {} Bitte gib Bescheid, dass du die Info erhalten hast indem du auf ✓ klickst.",
|
"Die Ausfahrt von {} am {} um {} wurde abgesagt. {}",
|
||||||
update.cox.user.name,
|
update.cox.user.name,
|
||||||
update.trip.day,
|
update.trip.day,
|
||||||
update.trip.planned_starting_time,
|
update.trip.planned_starting_time,
|
||||||
|
@ -1,21 +1,9 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
use sqlx::SqlitePool;
|
||||||
use sqlx::{FromRow, SqlitePool};
|
|
||||||
|
|
||||||
use super::{
|
use super::{notification::Notification, trip::Trip, tripdetails::TripDetails, user::User};
|
||||||
notification::Notification,
|
|
||||||
trip::{Trip, TripWithUserAndType},
|
|
||||||
tripdetails::TripDetails,
|
|
||||||
user::{CoxUser, User},
|
|
||||||
};
|
|
||||||
use crate::model::tripdetails::{Action, CoxAtTrip::Yes};
|
use crate::model::tripdetails::{Action, CoxAtTrip::Yes};
|
||||||
|
|
||||||
#[derive(FromRow, Debug, Serialize, Deserialize, Clone)]
|
pub struct UserTrip {}
|
||||||
pub struct UserTrip {
|
|
||||||
pub user_id: Option<i64>,
|
|
||||||
pub user_note: Option<String>,
|
|
||||||
pub trip_details_id: i64,
|
|
||||||
pub created_at: String, // TODO: switch to NaiveDateTime
|
|
||||||
}
|
|
||||||
|
|
||||||
impl UserTrip {
|
impl UserTrip {
|
||||||
pub async fn create(
|
pub async fn create(
|
||||||
@ -78,13 +66,10 @@ impl UserTrip {
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
user_note.clone().unwrap()
|
user_note.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(trip) = Trip::find_by_trip_details(db, trip_details.id).await {
|
if let Some(trip) = Trip::find_by_trip_details(db, trip_details.id).await {
|
||||||
if user_note.is_none() {
|
|
||||||
// Don't show notification if we add guest (as only we are
|
|
||||||
// allowed to do so)
|
|
||||||
let cox = User::find_by_id(db, trip.cox_id as i32).await.unwrap();
|
let cox = User::find_by_id(db, trip.cox_id as i32).await.unwrap();
|
||||||
Notification::create(
|
Notification::create(
|
||||||
db,
|
db,
|
||||||
@ -98,7 +83,6 @@ impl UserTrip {
|
|||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
}
|
|
||||||
|
|
||||||
trip_details.check_free_spaces(db).await;
|
trip_details.check_free_spaces(db).await;
|
||||||
}
|
}
|
||||||
@ -106,34 +90,6 @@ impl UserTrip {
|
|||||||
Ok(name_newly_registered_person)
|
Ok(name_newly_registered_person)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn tripdetails(&self, db: &SqlitePool) -> TripDetails {
|
|
||||||
TripDetails::find_by_id(db, self.trip_details_id)
|
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn find_by_userid_and_trip_detail_id(
|
|
||||||
db: &SqlitePool,
|
|
||||||
user_id: i64,
|
|
||||||
trip_detail_id: i64,
|
|
||||||
) -> Option<Self> {
|
|
||||||
sqlx::query_as!(Self, "SELECT user_id, user_note, trip_details_id, created_at FROM user_trip WHERE user_id= ? AND trip_details_id = ?", user_id, trip_detail_id)
|
|
||||||
.fetch_one(db)
|
|
||||||
.await
|
|
||||||
.ok()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn self_delete(&self, db: &SqlitePool) -> Result<(), UserTripDeleteError> {
|
|
||||||
let trip_details = self.tripdetails(db).await;
|
|
||||||
if let Some(id) = self.user_id {
|
|
||||||
let user = User::find_by_id(db, id as i32).await.unwrap();
|
|
||||||
return Self::delete(db, &user, &trip_details, self.user_note.clone()).await;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(()) // TODO: fixme
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: cleaner code
|
|
||||||
pub async fn delete(
|
pub async fn delete(
|
||||||
db: &SqlitePool,
|
db: &SqlitePool,
|
||||||
user: &User,
|
user: &User,
|
||||||
@ -148,24 +104,7 @@ impl UserTrip {
|
|||||||
return Err(UserTripDeleteError::NotVisibleToUser);
|
return Err(UserTripDeleteError::NotVisibleToUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut trip_to_delete = None;
|
if let Some(name) = name {
|
||||||
let mut some_trip = None;
|
|
||||||
if let Some(trip) = Trip::find_by_trip_details(db, trip_details.id).await {
|
|
||||||
some_trip = Some(trip.clone());
|
|
||||||
// If trip is cancelled, and lost rower just unregistered, delete the trip
|
|
||||||
if TripDetails::find_by_id(db, trip_details.id)
|
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.cancelled()
|
|
||||||
{
|
|
||||||
let trip = TripWithUserAndType::from(db, trip.clone()).await;
|
|
||||||
if trip.rower.len() == 1 {
|
|
||||||
trip_to_delete = Some(trip.trip);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(name) = name.clone() {
|
|
||||||
if !trip_details.user_allowed_to_change(db, user).await {
|
if !trip_details.user_allowed_to_change(db, user).await {
|
||||||
return Err(UserTripDeleteError::NotAllowedToDeleteGuest);
|
return Err(UserTripDeleteError::NotAllowedToDeleteGuest);
|
||||||
}
|
}
|
||||||
@ -193,55 +132,6 @@ impl UserTrip {
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut add_info = "";
|
|
||||||
if let Some(trip) = &trip_to_delete {
|
|
||||||
let cox = User::find_by_id(db, trip.cox_id as i32).await.unwrap();
|
|
||||||
trip.delete(db, &CoxUser::new(db, cox).await.unwrap())
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
add_info = " Das war die letzte angemeldete Person. Nachdem nun alle Bescheid wissen, wird die Ausfahrt ab sofort nicht mehr angezeigt.";
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(trip) = some_trip {
|
|
||||||
let opt_cancelled = if trip_to_delete.is_some() {
|
|
||||||
"abgesagten "
|
|
||||||
} else {
|
|
||||||
""
|
|
||||||
};
|
|
||||||
if let Some(name) = name {
|
|
||||||
if !add_info.is_empty() {
|
|
||||||
let cox = User::find_by_id(db, trip.cox_id as i32).await.unwrap();
|
|
||||||
Notification::create(
|
|
||||||
db,
|
|
||||||
&cox,
|
|
||||||
&format!(
|
|
||||||
"Du hast {} von deiner {}Ausfahrt am {} abgemeldet.{}",
|
|
||||||
name, opt_cancelled, trip.day, add_info
|
|
||||||
),
|
|
||||||
"Abmeldung von deiner Ausfahrt",
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let cox = User::find_by_id(db, trip.cox_id as i32).await.unwrap();
|
|
||||||
Notification::create(
|
|
||||||
db,
|
|
||||||
&cox,
|
|
||||||
&format!(
|
|
||||||
"{} hat sich von deiner {}Ausfahrt am {} abgemeldet.{}",
|
|
||||||
user.name, opt_cancelled, trip.day, add_info
|
|
||||||
),
|
|
||||||
"Abmeldung von deiner Ausfahrt",
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -327,7 +327,7 @@
|
|||||||
<div id="trip{{ trip.trip_details_id }}">
|
<div id="trip{{ trip.trip_details_id }}">
|
||||||
{% if trip.max_people == 0 %}
|
{% if trip.max_people == 0 %}
|
||||||
{# --- border-[#f43f5e] bg-[#f43f5e] --- #}
|
{# --- border-[#f43f5e] bg-[#f43f5e] --- #}
|
||||||
{{ macros::box(participants=trip.rower,bg='[#f43f5e]',header='Absage', trip_details_id=trip.trip_details_id, allow_removing=loggedin_user.id == trip.cox_id) }}
|
{{ macros::box(participants=trip.rower,bg='[#f43f5e]',header='Absage') }}
|
||||||
{% else %}
|
{% else %}
|
||||||
{% set amount_cur_rower = trip.rower | length %}
|
{% set amount_cur_rower = trip.rower | length %}
|
||||||
{{ macros::box(participants=trip.rower, empty_seats=trip.max_people - amount_cur_rower, bg='primary-100', color='black', trip_details_id=trip.trip_details_id, allow_removing=loggedin_user.id == trip.cox_id) }}
|
{{ macros::box(participants=trip.rower, empty_seats=trip.max_people - amount_cur_rower, bg='primary-100', color='black', trip_details_id=trip.trip_details_id, allow_removing=loggedin_user.id == trip.cox_id) }}
|
||||||
|
Loading…
Reference in New Issue
Block a user