mirror of
https://github.com/Djeeberjr/fw-anwesenheit.git
synced 2026-05-03 03:31:56 +00:00
changed TallyID to a struct instead of a type alias
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
use alloc::string::String;
|
||||
use picoserve::{
|
||||
extract::{Json, State},
|
||||
response::{self, IntoResponse},
|
||||
@@ -6,26 +5,31 @@ use picoserve::{
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::{
|
||||
store::{Name, hex_string_to_tally_id},
|
||||
store::{Name, tally_id::TallyID},
|
||||
webserver::{app::AppState, sse::IDEvents},
|
||||
};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct NewMapping {
|
||||
id: String,
|
||||
id: TallyID,
|
||||
name: Name,
|
||||
}
|
||||
|
||||
/*
|
||||
* #[get("/api/idevent")]
|
||||
* #[get("/api/csv")]
|
||||
* #[get("/api/mapping")]
|
||||
* #[post("/api/mapping", format = "json", data = "<new_mapping>")]
|
||||
* struct NewMapping {
|
||||
* id: String,
|
||||
* name: Name,
|
||||
* }
|
||||
*/
|
||||
// struct MappingWrapper(IDMapping);
|
||||
//
|
||||
// impl Serialize for MappingWrapper {
|
||||
// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
// where
|
||||
// S: serde::Serializer,
|
||||
// {
|
||||
// use serde::ser::SerializeMap;
|
||||
// let mut map = serializer.serialize_map(Some(self.0.id_map.len()))?;
|
||||
// for (k, v) in &self.0.id_map {
|
||||
// map.serialize_entry(tally_id_to_hex_string(*k).unwrap().as_str(), &v)?;
|
||||
// }
|
||||
// map.end()
|
||||
// }
|
||||
// }
|
||||
|
||||
pub async fn get_mapping(State(state): State<AppState>) -> impl IntoResponse {
|
||||
let store = state.store.lock().await;
|
||||
@@ -37,8 +41,7 @@ pub async fn add_mapping(
|
||||
Json(data): Json<NewMapping>,
|
||||
) -> impl IntoResponse {
|
||||
let mut store = state.store.lock().await;
|
||||
let tally_id = hex_string_to_tally_id(&data.id).unwrap();
|
||||
store.mapping.add_mapping(tally_id, data.name);
|
||||
store.mapping.add_mapping(data.id, data.name);
|
||||
}
|
||||
|
||||
pub async fn get_idevent(State(state): State<AppState>) -> impl IntoResponse {
|
||||
|
||||
@@ -2,7 +2,7 @@ use embassy_time::{Duration, Timer};
|
||||
use log::warn;
|
||||
use picoserve::response;
|
||||
|
||||
use crate::{TallySubscriber, store::tally_id_to_hex_string};
|
||||
use crate::TallySubscriber;
|
||||
|
||||
pub struct IDEvents(pub TallySubscriber);
|
||||
|
||||
@@ -18,9 +18,8 @@ impl response::sse::EventSource for IDEvents {
|
||||
match sel.await {
|
||||
embassy_futures::select::Either::First(msg) => match msg {
|
||||
embassy_sync::pubsub::WaitResult::Message(id) => {
|
||||
writer
|
||||
.write_event("msg", tally_id_to_hex_string(id).unwrap().as_str())
|
||||
.await?
|
||||
let id_str: heapless::String<12> = id.into();
|
||||
writer.write_event("msg", id_str.as_str()).await?
|
||||
}
|
||||
embassy_sync::pubsub::WaitResult::Lagged(_) => {
|
||||
warn!("SSE subscriber got lagged");
|
||||
|
||||
Reference in New Issue
Block a user