From 6ea404845aeaee6d02513ce77e42eac5711080a8 Mon Sep 17 00:00:00 2001 From: Franz Dietrich Date: Wed, 31 Jan 2024 13:17:09 +0100 Subject: [PATCH] get dates for frontend --- terminwahl_front/src/main.rs | 24 +++++++++++++++++++----- terminwahl_front/src/requests.rs | 12 ++++++++++++ terminwahl_typen/src/lib.rs | 11 +++++++++++ 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/terminwahl_front/src/main.rs b/terminwahl_front/src/main.rs index 09d4842..4f46382 100644 --- a/terminwahl_front/src/main.rs +++ b/terminwahl_front/src/main.rs @@ -2,10 +2,10 @@ mod requests; use std::collections::{HashMap, HashSet}; use gloo::console::log; -use requests::{fetch_slots, fetch_teachers, fetch_unavailable, send_appointments}; +use requests::{fetch_dates, fetch_slots, fetch_teachers, fetch_unavailable, send_appointments}; use terminwahl_typen::{ - AppointmentSlot, AppointmentSlots, IdType, Nutzer, PlannedAppointment, RequestState, SlotId, - Teacher, Teachers, + AppointmentSlot, AppointmentSlots, Dates, IdType, Nutzer, PlannedAppointment, RequestState, + SlotId, Teacher, Teachers, }; use web_sys::HtmlInputElement; use yew::prelude::*; @@ -18,6 +18,8 @@ pub enum Msg { DataEntered(Nutzer), GetTeachers, ReceivedTeachers(Teachers), + GetDates, + ReceivedDates(Dates), GetSlots, ReceivedSlots(AppointmentSlots), Selected(PlannedAppointment), @@ -30,6 +32,7 @@ pub enum Msg { pub struct App { nutzer: Option, tmp_nutzer: Nutzer, + dates: Option, teachers: Option, slots: Option, appointments: HashMap, @@ -54,6 +57,7 @@ impl Component for App { let app = Self { appointments: HashMap::new(), slots: None, + dates: None, unavailable: None, teachers: None, nutzer: None, @@ -64,8 +68,8 @@ impl Component for App { }, successfully_saved: None, }; - ctx.link().send_message(Msg::GetTeachers); - ctx.link().send_message(Msg::GetSlots); + + ctx.link().send_message(Msg::GetDates); app } @@ -93,6 +97,16 @@ impl Component for App { self.teachers = Some(teachers); true } + Msg::GetDates => { + ctx.link().send_future(fetch_dates()); + false + } + Msg::ReceivedDates(dates) => { + self.dates = Some(dates); + ctx.link().send_message(Msg::GetTeachers); + ctx.link().send_message(Msg::GetSlots); + true + } Msg::GetSlots => { ctx.link().send_future(fetch_slots()); ctx.link().send_future(fetch_unavailable()); diff --git a/terminwahl_front/src/requests.rs b/terminwahl_front/src/requests.rs index edc7f1f..61dafba 100644 --- a/terminwahl_front/src/requests.rs +++ b/terminwahl_front/src/requests.rs @@ -3,6 +3,18 @@ use terminwahl_typen::{Nutzer, PlannedAppointment, RequestState}; use crate::Msg; +pub async fn fetch_dates() -> Result { + // Send the request to the specified URL. + let response = Request::get("/get/dates").send().await; + // Return the ZuordnungMessage with the given network object and the response. + let response = response + .map_err(|_| Msg::AppointmentsSent(RequestState::Error))? + .json() + .await + .map_err(|_| Msg::AppointmentsSent(RequestState::Error))?; + Ok(Msg::ReceivedDates(response)) +} + pub async fn fetch_teachers() -> Result { // Send the request to the specified URL. let response = Request::get("/get/teachers/1").send().await; diff --git a/terminwahl_typen/src/lib.rs b/terminwahl_typen/src/lib.rs index 55cdfec..03c62cf 100644 --- a/terminwahl_typen/src/lib.rs +++ b/terminwahl_typen/src/lib.rs @@ -85,3 +85,14 @@ impl Nutzer { !self.name.is_empty() && !self.email.is_empty() && !self.schueler.is_empty() } } + +#[derive(Debug, Deserialize, Serialize, Clone)] +pub struct Date { + id: IdType, + name: String, + subtitle: String, + start_time: NaiveDateTime, + end_time: NaiveDateTime, +} + +pub type Dates = Vec;