From 8780f2bfcfeac1a51d7fd6626e4bc8369da1d713 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sat, 18 Jan 2025 15:44:34 -0500 Subject: [PATCH] Remove now unused API endpoint --- src/main.rs | 65 ----------------------------------------------------- 1 file changed, 65 deletions(-) diff --git a/src/main.rs b/src/main.rs index 640a3bb..7edf201 100644 --- a/src/main.rs +++ b/src/main.rs @@ -194,70 +194,6 @@ struct PollChoiceResponse { votes: i32, } -#[derive(Debug, Clone, Serialize)] -struct PollResponse { - title: String, - choices: Vec, -} - -async fn view_current_poll(State(state): State) -> Response { - tracing::info!("Requesting current poll"); - - 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() { - let poll_config = current_poll.first().unwrap(); - let mut choices = vec![]; - - let find_vote_choice = |id: i32| { - if let Some(poll) = state.get_poll_votes_by_poll_id(current_poll[0].id) { - for choice in &poll.choices { - if choice.id == id { - return Some(choice.clone()); - } - } - } - - return None; - }; - - for choice in &poll_config.choices { - if let Some(vote_choice) = find_vote_choice(choice.id) { - choices.push(PollChoiceResponse { - id: choice.id, - name: choice.name.clone(), - url: choice.url.clone(), - votes: vote_choice.votes, - }); - } else { - choices.push(PollChoiceResponse { - id: choice.id, - name: choice.name.clone(), - url: choice.url.clone(), - votes: 0, - }); - } - } - - return Json(PollResponse { - title: current_poll.first().unwrap().title.clone(), - choices, - }) - .into_response(); - } - } - } - } - - (StatusCode::NOT_FOUND, "No poll is open right now!").into_response() -} - #[derive(Deserialize)] struct SubmitForm { choice: i32, @@ -524,7 +460,6 @@ async fn main() { let app = Router::new() .route("/votes/{slug}", post(leaderboard_submit_score)) .route("/votes/{slug}", get(view_votes)) - .route("/polls/current", get(view_current_poll)) .route("/polls/vote", post(vote_current_poll)) .route("/polls/frame/vote", get(poll_frame_vote)) .route("/polls/frame/results", get(poll_frame_results))