add first draft of cal
This commit is contained in:
33
src/rest/cal.rs
Normal file
33
src/rest/cal.rs
Normal file
@ -0,0 +1,33 @@
|
||||
use rocket::{get, routes, Route, State};
|
||||
use sqlx::SqlitePool;
|
||||
|
||||
use crate::model::planned_event::PlannedEvent;
|
||||
|
||||
#[get("/")]
|
||||
async fn index(db: &State<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:{}T{}Z",
|
||||
event.day, event.planned_starting_time
|
||||
));
|
||||
res.push_str(&format!("\nSUMMARY:{}", event.name));
|
||||
|
||||
res.push_str("\nEND:VEVENT");
|
||||
}
|
||||
|
||||
res.push_str("\nEND:VCALENDAR");
|
||||
res
|
||||
}
|
||||
|
||||
pub fn routes() -> Vec<Route> {
|
||||
routes![index]
|
||||
}
|
@ -21,6 +21,7 @@ use crate::model::{
|
||||
|
||||
mod admin;
|
||||
mod auth;
|
||||
mod cal;
|
||||
mod cox;
|
||||
mod faq;
|
||||
|
||||
@ -143,6 +144,7 @@ pub fn start(db: SqlitePool) -> Rocket<Build> {
|
||||
.mount("/cox", cox::routes())
|
||||
.mount("/admin", admin::routes())
|
||||
.mount("/faq", faq::routes())
|
||||
.mount("/cal", cal::routes())
|
||||
.mount("/public", FileServer::from("static/"))
|
||||
.register("/", catchers![unauthorized_error])
|
||||
.attach(Template::fairing())
|
||||
|
Reference in New Issue
Block a user