forked from Ruderverein-Donau-Linz/rowt
restructre
This commit is contained in:
@ -205,6 +205,31 @@ FROM user_trip WHERE trip_details_id = (SELECT trip_details_id FROM planned_even
|
||||
.await
|
||||
.unwrap(); //Okay, as PlannedEvent can only be created with proper DB backing
|
||||
}
|
||||
|
||||
pub async fn get_ics_feed(db: &SqlitePool) -> String {
|
||||
let mut res = String::from(
|
||||
r#"BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
PRODID:-//rudernlinz.at//Trips//DE"#,
|
||||
);
|
||||
|
||||
let events = PlannedEvent::all(db).await;
|
||||
for event in events {
|
||||
res.push_str("\nBEGIN:VEVENT");
|
||||
res.push_str(&format!("\nUID:{}@rudernlinz.at", event.id));
|
||||
res.push_str(&format!(
|
||||
"\nDTSTART;TZID=Europe/Vienna:{}T{}00",
|
||||
event.day.replace("-", ""),
|
||||
event.planned_starting_time.replace(":", "")
|
||||
));
|
||||
res.push_str(&format!("\nSUMMARY:{}", event.name));
|
||||
|
||||
res.push_str("\nEND:VEVENT");
|
||||
}
|
||||
|
||||
res.push_str("\nEND:VCALENDAR");
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@ -248,4 +273,12 @@ mod test {
|
||||
PlannedEvent::get_for_day(&pool, NaiveDate::from_ymd_opt(1970, 1, 1).unwrap()).await;
|
||||
assert_eq!(res.len(), 0);
|
||||
}
|
||||
|
||||
#[sqlx::test]
|
||||
fn test_ics() {
|
||||
let pool = testdb!();
|
||||
|
||||
let actual = PlannedEvent::get_ics_feed(&pool).await;
|
||||
assert_eq!("BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//rudernlinz.at//Trips//DE\nBEGIN:VEVENT\nUID:1@rudernlinz.at\nDTSTART;TZID=Europe/Vienna:19700101T100000\nSUMMARY:test-planned-event\nEND:VEVENT\nEND:VCALENDAR", actual);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user