From a25d26473af84ca05f8c260205175d9e1a429a37 Mon Sep 17 00:00:00 2001 From: Djeeberjr Date: Tue, 20 May 2025 13:19:27 +0200 Subject: [PATCH] prevent adding empty id mapping --- src/webserver.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/webserver.rs b/src/webserver.rs index f7b37c7..dd156b1 100644 --- a/src/webserver.rs +++ b/src/webserver.rs @@ -114,10 +114,19 @@ async fn get_mapping(store: &State>>) -> Json { } #[post("/api/mapping", format = "json", data = "")] -async fn add_mapping(store: &State>>, new_mapping: Json) { +async fn add_mapping(store: &State>>, new_mapping: Json) -> Status { + if new_mapping.id.is_empty() + || new_mapping.name.first.is_empty() + || new_mapping.name.last.is_empty() + { + return Status::BadRequest; + } + store .lock() .await .mapping .add_mapping(TallyID(new_mapping.id.clone()), new_mapping.name.clone()); + + Status::Created }