datum hinzu fügen
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
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>) -> Result<HttpResponse, Error> {
|
||||
let tasks = db::read::get_teachers(&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)?;
|
||||
|
||||
@@ -17,8 +22,12 @@ pub async fn get_subjects_json(pool: web::Data<Pool>) -> Result<HttpResponse, Er
|
||||
Ok(HttpResponse::Ok().json(tasks))
|
||||
}
|
||||
|
||||
pub async fn get_slots_json(pool: web::Data<Pool>) -> Result<HttpResponse, Error> {
|
||||
let tasks = db::read::get_slots(&pool)
|
||||
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)?;
|
||||
|
||||
|
||||
@@ -10,12 +10,17 @@ use terminwahl_typen::{
|
||||
|
||||
use super::Pool;
|
||||
|
||||
pub async fn get_teachers(db: &Pool) -> Result<Teachers, sqlx::Error> {
|
||||
pub async fn get_teachers(db: &Pool, date_id: IdType) -> Result<Teachers, sqlx::Error> {
|
||||
query_as!(
|
||||
Teacher,
|
||||
r#"
|
||||
SELECT *
|
||||
FROM `teachers`"#,
|
||||
SELECT
|
||||
id,
|
||||
ansprache,
|
||||
last_name,
|
||||
subject_id
|
||||
FROM `teachers` JOIN teacher_dates ON teachers.id = teacher_dates.teacher_id where date_id = ?"#,
|
||||
date_id
|
||||
)
|
||||
.fetch_all(db)
|
||||
.await
|
||||
@@ -44,12 +49,13 @@ pub async fn get_subjects(db: &Pool) -> Result<Subjects, sqlx::Error> {
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_slots(db: &Pool) -> Result<AppointmentSlots, sqlx::Error> {
|
||||
pub async fn get_slots(db: &Pool, date_id: IdType) -> Result<AppointmentSlots, sqlx::Error> {
|
||||
match query_as!(
|
||||
AppointmentSlot,
|
||||
r#"
|
||||
SELECT *
|
||||
FROM `appointment_slots`"#,
|
||||
SELECT id, start_time, end_time, date_id
|
||||
FROM `appointment_slots` where date_id = ?"#,
|
||||
date_id
|
||||
)
|
||||
.fetch_all(db)
|
||||
.await
|
||||
@@ -109,8 +115,11 @@ pub struct AssignedAppointment {
|
||||
nutzer: Nutzer,
|
||||
}
|
||||
|
||||
pub async fn get_all_teachers(db: &Pool) -> Result<Vec<TeacherWithAppointments>, sqlx::Error> {
|
||||
let teachers = get_teachers(db).await?;
|
||||
pub async fn get_all_teachers(
|
||||
db: &Pool,
|
||||
date_id: IdType,
|
||||
) -> Result<Vec<TeacherWithAppointments>, sqlx::Error> {
|
||||
let teachers = get_teachers(db, date_id).await?;
|
||||
let mut response = Vec::new();
|
||||
|
||||
for teacher in teachers.into_iter() {
|
||||
|
||||
@@ -70,12 +70,16 @@ async fn main() -> std::io::Result<()> {
|
||||
.wrap(session_store)
|
||||
.wrap(error_handlers)
|
||||
.service(
|
||||
web::resource("/get/teachers").route(web::get().to(api::read::get_teachers_json)),
|
||||
web::resource("/get/teachers/{date_key}")
|
||||
.route(web::get().to(api::read::get_teachers_json)),
|
||||
)
|
||||
.service(
|
||||
web::resource("/get/subjects").route(web::get().to(api::read::get_subjects_json)),
|
||||
)
|
||||
.service(web::resource("/get/slots").route(web::get().to(api::read::get_slots_json)))
|
||||
.service(
|
||||
web::resource("/get/slots/{date_key}")
|
||||
.route(web::get().to(api::read::get_slots_json)),
|
||||
)
|
||||
.service(
|
||||
web::resource("/get/unavailable")
|
||||
.route(web::get().to(api::read::get_unavailable_json)),
|
||||
|
||||
@@ -60,12 +60,12 @@ pub async fn export_appointments(
|
||||
_mailer: web::Data<AsyncSmtpTransport<Tokio1Executor>>,
|
||||
handlebars: web::Data<Handlebars<'_>>,
|
||||
css: web::Data<CssPath>,
|
||||
path: web::Path<String>,
|
||||
path: web::Path<(String, IdType)>,
|
||||
) -> Result<HttpResponse, error::Error> {
|
||||
let password = path.into_inner();
|
||||
let (password, date_id) = path.into_inner();
|
||||
dbg!(&password);
|
||||
if password == "AllExport1517" {
|
||||
match get_all_teachers(&pool).await {
|
||||
match get_all_teachers(&pool, date_id).await {
|
||||
Ok(teachers) => {
|
||||
dbg!(&teachers);
|
||||
let data = json!({
|
||||
|
||||
Reference in New Issue
Block a user