changed TallyID to a struct instead of a type alias

This commit is contained in:
2025-10-08 16:14:10 +02:00
parent 0f5ca88ae4
commit dfe5197ab8
7 changed files with 118 additions and 61 deletions

View File

@@ -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 {