Datum auswählbar machen
This commit is contained in:
@@ -40,3 +40,11 @@ pub async fn get_unavailable_json(pool: web::Data<Pool>) -> Result<HttpResponse,
|
||||
|
||||
Ok(HttpResponse::Ok().json(tasks))
|
||||
}
|
||||
|
||||
pub async fn get_dates_json(pool: web::Data<Pool>) -> Result<HttpResponse, Error> {
|
||||
let dates = db::read::get_dates(&pool)
|
||||
.await
|
||||
.map_err(error::ErrorInternalServerError)?;
|
||||
|
||||
Ok(HttpResponse::Ok().json(dates))
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@ use serde::{Deserialize, Serialize};
|
||||
use sqlx::query_as;
|
||||
|
||||
use terminwahl_typen::{
|
||||
AppointmentSlot, AppointmentSlots, IdType, Nutzer, SlotId, Subject, Subjects, Teacher, Teachers,
|
||||
AppointmentSlot, AppointmentSlots, Date, Dates, IdType, Nutzer, SlotId, Subject, Subjects,
|
||||
Teacher, Teachers,
|
||||
};
|
||||
|
||||
use super::Pool;
|
||||
@@ -93,7 +94,20 @@ pub async fn get_unavailable(db: &Pool) -> Result<HashSet<SlotId>, sqlx::Error>
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_dates(db: &Pool) -> Result<Dates, sqlx::Error> {
|
||||
match query_as!(
|
||||
Date,
|
||||
r#"
|
||||
SELECT *
|
||||
FROM `date`;"#,
|
||||
)
|
||||
.fetch_all(db)
|
||||
.await
|
||||
{
|
||||
Ok(elems) => Ok(elems.into_iter().collect()),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
#[derive(Debug, Deserialize, Serialize, Clone)]
|
||||
pub struct TeacherWithAppointments {
|
||||
teacher: Teacher,
|
||||
|
||||
@@ -69,6 +69,7 @@ async fn main() -> std::io::Result<()> {
|
||||
.wrap(Logger::default())
|
||||
.wrap(session_store)
|
||||
.wrap(error_handlers)
|
||||
.service(web::resource("/get/dates").route(web::get().to(api::read::get_dates_json)))
|
||||
.service(
|
||||
web::resource("/get/teachers/{date_key}")
|
||||
.route(web::get().to(api::read::get_teachers_json)),
|
||||
|
||||
Reference in New Issue
Block a user