nicer-cal #573

Merged
philipp merged 3 commits from nicer-cal into staging 2024-06-06 07:11:34 +02:00
3 changed files with 27 additions and 2 deletions
Showing only changes of commit fa14cfbf83 - Show all commits

View File

@ -343,6 +343,10 @@ WHERE trip_details.id=?
Ok(()) Ok(())
} }
pub fn is_cancelled(&self) -> bool {
self.max_people == 0
}
pub async fn get_ics_feed(db: &SqlitePool) -> String { pub async fn get_ics_feed(db: &SqlitePool) -> String {
let mut calendar = ICalendar::new("2.0", "ics-rs"); let mut calendar = ICalendar::new("2.0", "ics-rs");
@ -355,7 +359,20 @@ WHERE trip_details.id=?
event.day.replace('-', ""), event.day.replace('-', ""),
event.planned_starting_time.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); calendar.add_event(vevent);
} }
let mut buf = Vec::new(); let mut buf = Vec::new();

View File

@ -7,6 +7,7 @@ use sqlx::{FromRow, SqlitePool};
use super::{ use super::{
notification::Notification, notification::Notification,
trip::{Trip, TripWithUserAndType}, trip::{Trip, TripWithUserAndType},
triptype::TripType,
}; };
#[derive(FromRow, Debug, Serialize, Deserialize)] #[derive(FromRow, Debug, Serialize, Deserialize)]
@ -51,6 +52,13 @@ WHERE id like ?
.ok() .ok()
} }
pub async fn triptype(&self, db: &SqlitePool) -> Option<TripType> {
match self.trip_type_id {
None => None,
Some(id) => TripType::find_by_id(db, id).await,
}
}
pub async fn find_by_startingdatetime( pub async fn find_by_startingdatetime(
db: &SqlitePool, db: &SqlitePool,
day: String, day: String,

View File

@ -4,7 +4,7 @@ use sqlx::{FromRow, SqlitePool};
#[derive(FromRow, Debug, Serialize, Deserialize, Clone)] #[derive(FromRow, Debug, Serialize, Deserialize, Clone)]
pub struct TripType { pub struct TripType {
pub id: i64, pub id: i64,
name: String, pub name: String,
desc: String, desc: String,
question: String, question: String,
icon: String, icon: String,