From 9a31bf8221ad26a0e0e70cf1c387ca48abb3fea3 Mon Sep 17 00:00:00 2001 From: Denys Konovalov Date: Sun, 5 Dec 2021 16:41:11 +0100 Subject: [PATCH] moved date management to frontend --- src/main.rs | 83 ++++++----------------------------------------------- 1 file changed, 8 insertions(+), 75 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2812f4e..d557ee7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,7 +13,6 @@ extern crate reqwest; extern crate serde; extern crate serde_json; -use chrono::{Duration, Local}; use indiware_connector as timetable_connector; use jsonwebtoken::{decode, DecodingKey, Validation}; use keycloak_connector::KeycloakUser; @@ -163,7 +162,7 @@ async fn login( keycloak_connector::login(credentials).await } -#[get("/")] +#[get("/latest")] async fn get_latest_timetable( conn: DbConn, _key: ApiKey<'_>, @@ -172,37 +171,8 @@ async fn get_latest_timetable( Json::from(timetable) } -#[get("/today")] -async fn get_today_timetable( - conn: DbConn, - _key: ApiKey<'_>, -) -> Json> { - let timetable = timetable_connector::get_timetable( - conn, - format!("PlanKl{}.xml", Local::today().format("%Y%m%d")), - ) - .await; - Json::from(timetable) -} - -#[get("/tomorrow")] -async fn get_tomorrow_timetable( - conn: DbConn, - _key: ApiKey<'_>, -) -> Json> { - let timetable = timetable_connector::get_timetable( - conn, - format!( - "PlanKl{}.xml", - (Local::today() + Duration::days(1)).format("%Y%m%d") - ), - ) - .await; - Json::from(timetable) -} - -#[get("/date/")] -async fn get_daily_timetable( +#[get("/")] +async fn get_timetable_file( conn: DbConn, _key: ApiKey<'_>, date: String, @@ -211,7 +181,7 @@ async fn get_daily_timetable( Json::from(timetable) } -#[get("/")] +#[get("/latest/")] async fn get_latest_class_timetable( conn: DbConn, class: String, @@ -222,41 +192,8 @@ async fn get_latest_class_timetable( Json::from(timetable) } -#[get("//today")] -async fn get_today_class_timetable( - conn: DbConn, - class: String, - _key: ApiKey<'_>, -) -> Json { - let timetable = timetable_connector::get_class_timetable( - conn, - class, - format!("PlanKl{}.xml", Local::today().format("%Y%m%d")), - ) - .await; - Json::from(timetable) -} - -#[get("//tomorrow")] -async fn get_tomorrow_class_timetable( - conn: DbConn, - class: String, - _key: ApiKey<'_>, -) -> Json { - let timetable = timetable_connector::get_class_timetable( - conn, - class, - format!( - "PlanKl{}.xml", - (Local::today() + Duration::days(1)).format("%Y%m%d") - ), - ) - .await; - Json::from(timetable) -} - -#[get("//date/")] -async fn get_daily_class_timetable( +#[get("//")] +async fn get_class_timetable_file( conn: DbConn, class: String, _key: ApiKey<'_>, @@ -293,12 +230,8 @@ fn rocket() -> _ { routes![ get_latest_timetable, get_latest_class_timetable, - get_today_timetable, - get_today_class_timetable, - get_tomorrow_timetable, - get_tomorrow_class_timetable, - get_daily_timetable, - get_daily_class_timetable + get_timetable_file, + get_class_timetable_file, ], ) .mount("/api/classes", routes![get_classes])