get dates for frontend

This commit is contained in:
Franz Dietrich 2024-01-31 13:17:09 +01:00
parent f79cbc36c4
commit 6ea404845a
3 changed files with 42 additions and 5 deletions

View File

@ -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<Nutzer>,
tmp_nutzer: Nutzer,
dates: Option<Dates>,
teachers: Option<Teachers>,
slots: Option<AppointmentSlots>,
appointments: HashMap<SlotId, PlannedAppointment>,
@ -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());

View File

@ -3,6 +3,18 @@ use terminwahl_typen::{Nutzer, PlannedAppointment, RequestState};
use crate::Msg;
pub async fn fetch_dates() -> Result<Msg, Msg> {
// 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<Msg, Msg> {
// Send the request to the specified URL.
let response = Request::get("/get/teachers/1").send().await;

View File

@ -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<Date>;