From 0904f5056781c496a8420fdbcaf03345bf2ab834 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sat, 18 Jan 2025 14:38:10 -0500 Subject: [PATCH] Some poll code cleanup --- src/main.rs | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index 15e4c96..d4ecdb7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,6 @@ use axum::{ use serde::{Deserialize, Serialize}; use std::net::SocketAddr; use std::sync::{Arc, Mutex}; -use axum::extract::rejection::JsonRejection; use axum::http::StatusCode; use axum::response::{IntoResponse, Response}; @@ -111,11 +110,9 @@ impl AppState { fn get_poll_config_by_id(id: i32) -> Option { if let Ok(data) = std::fs::read_to_string("polls.json") { if let Ok(config) = serde_json::from_str::(&data) { - if let Some(current_poll) = config.current_poll { - let current_poll: Vec<&PollConfig> = config.polls.iter().filter(|poll| poll.id == current_poll).collect(); - if !current_poll.is_empty() { - return Some(<&PollConfig>::clone(current_poll.first().unwrap()).clone()); - } + let current_poll: Vec<&PollConfig> = config.polls.iter().filter(|poll| poll.id == id).collect(); + if !current_poll.is_empty() { + return Some(<&PollConfig>::clone(current_poll.first().unwrap()).clone()); } } } @@ -124,11 +121,7 @@ impl AppState { } fn get_poll_votes_by_poll_id(&self, poll_id: i32) -> Option { - let mut poll_votes = self.poll_votes.lock().unwrap(); - - let Some(poll_config) = AppState::get_poll_config_by_id(poll_id) else { - return None; - }; + let poll_votes = self.poll_votes.lock().unwrap(); for existing_poll in &poll_votes.polls { if existing_poll.id == poll_id {