get dates for frontend
This commit is contained in:
parent
f79cbc36c4
commit
6ea404845a
@ -2,10 +2,10 @@ mod requests;
|
|||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
|
||||||
use gloo::console::log;
|
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::{
|
use terminwahl_typen::{
|
||||||
AppointmentSlot, AppointmentSlots, IdType, Nutzer, PlannedAppointment, RequestState, SlotId,
|
AppointmentSlot, AppointmentSlots, Dates, IdType, Nutzer, PlannedAppointment, RequestState,
|
||||||
Teacher, Teachers,
|
SlotId, Teacher, Teachers,
|
||||||
};
|
};
|
||||||
use web_sys::HtmlInputElement;
|
use web_sys::HtmlInputElement;
|
||||||
use yew::prelude::*;
|
use yew::prelude::*;
|
||||||
@ -18,6 +18,8 @@ pub enum Msg {
|
|||||||
DataEntered(Nutzer),
|
DataEntered(Nutzer),
|
||||||
GetTeachers,
|
GetTeachers,
|
||||||
ReceivedTeachers(Teachers),
|
ReceivedTeachers(Teachers),
|
||||||
|
GetDates,
|
||||||
|
ReceivedDates(Dates),
|
||||||
GetSlots,
|
GetSlots,
|
||||||
ReceivedSlots(AppointmentSlots),
|
ReceivedSlots(AppointmentSlots),
|
||||||
Selected(PlannedAppointment),
|
Selected(PlannedAppointment),
|
||||||
@ -30,6 +32,7 @@ pub enum Msg {
|
|||||||
pub struct App {
|
pub struct App {
|
||||||
nutzer: Option<Nutzer>,
|
nutzer: Option<Nutzer>,
|
||||||
tmp_nutzer: Nutzer,
|
tmp_nutzer: Nutzer,
|
||||||
|
dates: Option<Dates>,
|
||||||
teachers: Option<Teachers>,
|
teachers: Option<Teachers>,
|
||||||
slots: Option<AppointmentSlots>,
|
slots: Option<AppointmentSlots>,
|
||||||
appointments: HashMap<SlotId, PlannedAppointment>,
|
appointments: HashMap<SlotId, PlannedAppointment>,
|
||||||
@ -54,6 +57,7 @@ impl Component for App {
|
|||||||
let app = Self {
|
let app = Self {
|
||||||
appointments: HashMap::new(),
|
appointments: HashMap::new(),
|
||||||
slots: None,
|
slots: None,
|
||||||
|
dates: None,
|
||||||
unavailable: None,
|
unavailable: None,
|
||||||
teachers: None,
|
teachers: None,
|
||||||
nutzer: None,
|
nutzer: None,
|
||||||
@ -64,8 +68,8 @@ impl Component for App {
|
|||||||
},
|
},
|
||||||
successfully_saved: None,
|
successfully_saved: None,
|
||||||
};
|
};
|
||||||
ctx.link().send_message(Msg::GetTeachers);
|
|
||||||
ctx.link().send_message(Msg::GetSlots);
|
ctx.link().send_message(Msg::GetDates);
|
||||||
app
|
app
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,6 +97,16 @@ impl Component for App {
|
|||||||
self.teachers = Some(teachers);
|
self.teachers = Some(teachers);
|
||||||
true
|
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 => {
|
Msg::GetSlots => {
|
||||||
ctx.link().send_future(fetch_slots());
|
ctx.link().send_future(fetch_slots());
|
||||||
ctx.link().send_future(fetch_unavailable());
|
ctx.link().send_future(fetch_unavailable());
|
||||||
|
@ -3,6 +3,18 @@ use terminwahl_typen::{Nutzer, PlannedAppointment, RequestState};
|
|||||||
|
|
||||||
use crate::Msg;
|
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> {
|
pub async fn fetch_teachers() -> Result<Msg, Msg> {
|
||||||
// Send the request to the specified URL.
|
// Send the request to the specified URL.
|
||||||
let response = Request::get("/get/teachers/1").send().await;
|
let response = Request::get("/get/teachers/1").send().await;
|
||||||
|
@ -85,3 +85,14 @@ impl Nutzer {
|
|||||||
!self.name.is_empty() && !self.email.is_empty() && !self.schueler.is_empty()
|
!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>;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user