restructre
This commit is contained in:
parent
9dc43d2d32
commit
05b65b2f67
@ -205,6 +205,31 @@ FROM user_trip WHERE trip_details_id = (SELECT trip_details_id FROM planned_even
|
|||||||
.await
|
.await
|
||||||
.unwrap(); //Okay, as PlannedEvent can only be created with proper DB backing
|
.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)]
|
#[cfg(test)]
|
||||||
@ -248,4 +273,12 @@ mod test {
|
|||||||
PlannedEvent::get_for_day(&pool, NaiveDate::from_ymd_opt(1970, 1, 1).unwrap()).await;
|
PlannedEvent::get_for_day(&pool, NaiveDate::from_ymd_opt(1970, 1, 1).unwrap()).await;
|
||||||
assert_eq!(res.len(), 0);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,25 @@
|
|||||||
use rocket::Route;
|
use rocket::{get, routes, Route, State};
|
||||||
|
use sqlx::SqlitePool;
|
||||||
|
|
||||||
|
use crate::model::log::Log;
|
||||||
|
|
||||||
pub mod planned_event;
|
pub mod planned_event;
|
||||||
pub mod rss;
|
|
||||||
pub mod user;
|
pub mod user;
|
||||||
|
|
||||||
|
#[get("/rss?<key>")]
|
||||||
|
async fn rss(db: &State<SqlitePool>, key: Option<&str>) -> String {
|
||||||
|
match key {
|
||||||
|
Some(key) if key.eq("G9h/f2MFEr408IaB4Yd67/maVSsnAJNjcaZ2Tzl5Vo=") => {
|
||||||
|
Log::generate_feed(db).await
|
||||||
|
}
|
||||||
|
_ => "Not allowed".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn routes() -> Vec<Route> {
|
pub fn routes() -> Vec<Route> {
|
||||||
let mut ret = Vec::new();
|
let mut ret = Vec::new();
|
||||||
ret.append(&mut user::routes());
|
ret.append(&mut user::routes());
|
||||||
ret.append(&mut planned_event::routes());
|
ret.append(&mut planned_event::routes());
|
||||||
ret.append(&mut rss::routes());
|
ret.append(&mut routes![rss]);
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
use crate::rest::Log;
|
|
||||||
use rocket::{get, routes, Route, State};
|
|
||||||
use sqlx::SqlitePool;
|
|
||||||
|
|
||||||
#[get("/rss?<key>")]
|
|
||||||
async fn index(db: &State<SqlitePool>, key: Option<&str>) -> String {
|
|
||||||
match key {
|
|
||||||
Some(key) if key.eq("G9h/f2MFEr408IaB4Yd67/maVSsnAJNjcaZ2Tzl5Vo=") => {
|
|
||||||
Log::generate_feed(db).await
|
|
||||||
}
|
|
||||||
_ => "Not allowed".to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn routes() -> Vec<Route> {
|
|
||||||
routes![index]
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
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;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
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn routes() -> Vec<Route> {
|
|
||||||
routes![index]
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
use rocket::{get, routes, Route};
|
|
||||||
use rocket_dyn_templates::{context, Template};
|
|
||||||
|
|
||||||
use crate::model::user::User;
|
|
||||||
|
|
||||||
#[get("/")]
|
|
||||||
async fn index(user: User) -> Template {
|
|
||||||
Template::render("faq", context!(loggedin_user: user))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn routes() -> Vec<Route> {
|
|
||||||
routes![index]
|
|
||||||
}
|
|
19
src/rest/misc.rs
Normal file
19
src/rest/misc.rs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
use rocket::{get, routes, Route, State};
|
||||||
|
use rocket_dyn_templates::{context, Template};
|
||||||
|
use sqlx::SqlitePool;
|
||||||
|
|
||||||
|
use crate::model::{planned_event::PlannedEvent, user::User};
|
||||||
|
|
||||||
|
#[get("/faq")]
|
||||||
|
async fn faq(user: User) -> Template {
|
||||||
|
Template::render("faq", context!(loggedin_user: user))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[get("/cal")]
|
||||||
|
async fn cal(db: &State<SqlitePool>) -> String {
|
||||||
|
PlannedEvent::get_ics_feed(db).await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn routes() -> Vec<Route> {
|
||||||
|
routes![faq, cal]
|
||||||
|
}
|
@ -21,9 +21,8 @@ use crate::model::{
|
|||||||
|
|
||||||
mod admin;
|
mod admin;
|
||||||
mod auth;
|
mod auth;
|
||||||
mod cal;
|
|
||||||
mod cox;
|
mod cox;
|
||||||
mod faq;
|
mod misc;
|
||||||
|
|
||||||
fn amount_days_to_show(is_cox: bool) -> i64 {
|
fn amount_days_to_show(is_cox: bool) -> i64 {
|
||||||
if is_cox {
|
if is_cox {
|
||||||
@ -143,8 +142,7 @@ pub fn start(db: SqlitePool) -> Rocket<Build> {
|
|||||||
.mount("/auth", auth::routes())
|
.mount("/auth", auth::routes())
|
||||||
.mount("/cox", cox::routes())
|
.mount("/cox", cox::routes())
|
||||||
.mount("/admin", admin::routes())
|
.mount("/admin", admin::routes())
|
||||||
.mount("/faq", faq::routes())
|
.mount("/", misc::routes())
|
||||||
.mount("/cal", cal::routes())
|
|
||||||
.mount("/public", FileServer::from("static/"))
|
.mount("/public", FileServer::from("static/"))
|
||||||
.register("/", catchers![unauthorized_error])
|
.register("/", catchers![unauthorized_error])
|
||||||
.attach(Template::fairing())
|
.attach(Template::fairing())
|
||||||
|
Loading…
Reference in New Issue
Block a user