moved date management to frontend

This commit is contained in:
Denys Konovalov 2021-12-05 16:41:11 +01:00
parent 2cf861b04c
commit 9a31bf8221

@ -13,7 +13,6 @@ extern crate reqwest;
extern crate serde; extern crate serde;
extern crate serde_json; extern crate serde_json;
use chrono::{Duration, Local};
use indiware_connector as timetable_connector; use indiware_connector as timetable_connector;
use jsonwebtoken::{decode, DecodingKey, Validation}; use jsonwebtoken::{decode, DecodingKey, Validation};
use keycloak_connector::KeycloakUser; use keycloak_connector::KeycloakUser;
@ -163,7 +162,7 @@ async fn login(
keycloak_connector::login(credentials).await keycloak_connector::login(credentials).await
} }
#[get("/")] #[get("/latest")]
async fn get_latest_timetable( async fn get_latest_timetable(
conn: DbConn, conn: DbConn,
_key: ApiKey<'_>, _key: ApiKey<'_>,
@ -172,37 +171,8 @@ async fn get_latest_timetable(
Json::from(timetable) Json::from(timetable)
} }
#[get("/today")] #[get("/<date>")]
async fn get_today_timetable( async fn get_timetable_file(
conn: DbConn,
_key: ApiKey<'_>,
) -> Json<Vec<timetable_connector::Timetable>> {
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<Vec<timetable_connector::Timetable>> {
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/<date>")]
async fn get_daily_timetable(
conn: DbConn, conn: DbConn,
_key: ApiKey<'_>, _key: ApiKey<'_>,
date: String, date: String,
@ -211,7 +181,7 @@ async fn get_daily_timetable(
Json::from(timetable) Json::from(timetable)
} }
#[get("/<class>")] #[get("/latest/<class>")]
async fn get_latest_class_timetable( async fn get_latest_class_timetable(
conn: DbConn, conn: DbConn,
class: String, class: String,
@ -222,41 +192,8 @@ async fn get_latest_class_timetable(
Json::from(timetable) Json::from(timetable)
} }
#[get("/<class>/today")] #[get("/<date>/<class>")]
async fn get_today_class_timetable( async fn get_class_timetable_file(
conn: DbConn,
class: String,
_key: ApiKey<'_>,
) -> Json<timetable_connector::TimetableData> {
let timetable = timetable_connector::get_class_timetable(
conn,
class,
format!("PlanKl{}.xml", Local::today().format("%Y%m%d")),
)
.await;
Json::from(timetable)
}
#[get("/<class>/tomorrow")]
async fn get_tomorrow_class_timetable(
conn: DbConn,
class: String,
_key: ApiKey<'_>,
) -> Json<timetable_connector::TimetableData> {
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("/<class>/date/<date>")]
async fn get_daily_class_timetable(
conn: DbConn, conn: DbConn,
class: String, class: String,
_key: ApiKey<'_>, _key: ApiKey<'_>,
@ -293,12 +230,8 @@ fn rocket() -> _ {
routes![ routes![
get_latest_timetable, get_latest_timetable,
get_latest_class_timetable, get_latest_class_timetable,
get_today_timetable, get_timetable_file,
get_today_class_timetable, get_class_timetable_file,
get_tomorrow_timetable,
get_tomorrow_class_timetable,
get_daily_timetable,
get_daily_class_timetable
], ],
) )
.mount("/api/classes", routes![get_classes]) .mount("/api/classes", routes![get_classes])