From fa14cfbf83ab8405a94cf40d3985ad57da85bf78 Mon Sep 17 00:00:00 2001 From: philipp Date: Thu, 6 Jun 2024 06:47:41 +0200 Subject: [PATCH] add cancellation, trip_type and notes to cal export --- src/model/event.rs | 19 ++++++++++++++++++- src/model/tripdetails.rs | 8 ++++++++ src/model/triptype.rs | 2 +- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/model/event.rs b/src/model/event.rs index f03ada6..bec7892 100644 --- a/src/model/event.rs +++ b/src/model/event.rs @@ -343,6 +343,10 @@ WHERE trip_details.id=? Ok(()) } + pub fn is_cancelled(&self) -> bool { + self.max_people == 0 + } + pub async fn get_ics_feed(db: &SqlitePool) -> String { let mut calendar = ICalendar::new("2.0", "ics-rs"); @@ -355,7 +359,20 @@ WHERE trip_details.id=? event.day.replace('-', ""), event.planned_starting_time.replace(':', "") ))); - vevent.push(Summary::new(event.name)); + let mut name = String::new(); + if event.is_cancelled() { + name.push_str("ABGESAGT :-( "); + } + name.push_str(&format!("{} ", event.name)); + + let tripdetails = event.trip_details(db).await; + if let Some(triptype) = tripdetails.triptype(db).await { + name.push_str(&format!("• {} ", triptype.name)) + } + if let Some(notes) = tripdetails.notes { + name.push_str(&format!("({notes}) ")) + } + vevent.push(Summary::new(name)); calendar.add_event(vevent); } let mut buf = Vec::new(); diff --git a/src/model/tripdetails.rs b/src/model/tripdetails.rs index df1238e..ea4d601 100644 --- a/src/model/tripdetails.rs +++ b/src/model/tripdetails.rs @@ -7,6 +7,7 @@ use sqlx::{FromRow, SqlitePool}; use super::{ notification::Notification, trip::{Trip, TripWithUserAndType}, + triptype::TripType, }; #[derive(FromRow, Debug, Serialize, Deserialize)] @@ -51,6 +52,13 @@ WHERE id like ? .ok() } + pub async fn triptype(&self, db: &SqlitePool) -> Option { + match self.trip_type_id { + None => None, + Some(id) => TripType::find_by_id(db, id).await, + } + } + pub async fn find_by_startingdatetime( db: &SqlitePool, day: String, diff --git a/src/model/triptype.rs b/src/model/triptype.rs index f7aaf94..370fe19 100644 --- a/src/model/triptype.rs +++ b/src/model/triptype.rs @@ -4,7 +4,7 @@ use sqlx::{FromRow, SqlitePool}; #[derive(FromRow, Debug, Serialize, Deserialize, Clone)] pub struct TripType { pub id: i64, - name: String, + pub name: String, desc: String, question: String, icon: String,