51 lines
1.4 KiB
Rust
51 lines
1.4 KiB
Rust
use actix_web::{error, web, Error, HttpResponse};
|
|
use terminwahl_typen::IdType;
|
|
|
|
use crate::db::{self, Pool};
|
|
|
|
pub async fn get_teachers_json(
|
|
pool: web::Data<Pool>,
|
|
path: web::Path<IdType>,
|
|
) -> Result<HttpResponse, Error> {
|
|
let date_id = path.into_inner();
|
|
let tasks = db::read::get_teachers(&pool, date_id)
|
|
.await
|
|
.map_err(error::ErrorInternalServerError)?;
|
|
|
|
Ok(HttpResponse::Ok().json(tasks))
|
|
}
|
|
pub async fn get_subjects_json(pool: web::Data<Pool>) -> Result<HttpResponse, Error> {
|
|
let tasks = db::read::get_subjects(&pool)
|
|
.await
|
|
.map_err(error::ErrorInternalServerError)?;
|
|
|
|
Ok(HttpResponse::Ok().json(tasks))
|
|
}
|
|
|
|
pub async fn get_slots_json(
|
|
pool: web::Data<Pool>,
|
|
path: web::Path<IdType>,
|
|
) -> Result<HttpResponse, Error> {
|
|
let date_id = path.into_inner();
|
|
let tasks = db::read::get_slots(&pool, date_id)
|
|
.await
|
|
.map_err(error::ErrorInternalServerError)?;
|
|
|
|
Ok(HttpResponse::Ok().json(tasks))
|
|
}
|
|
pub async fn get_unavailable_json(pool: web::Data<Pool>) -> Result<HttpResponse, Error> {
|
|
let tasks = db::read::get_unavailable(&pool)
|
|
.await
|
|
.map_err(error::ErrorInternalServerError)?;
|
|
|
|
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))
|
|
}
|