Remove now unused API endpoint
This commit is contained in:
parent
cdb1b35ced
commit
8780f2bfcf
1 changed files with 0 additions and 65 deletions
65
src/main.rs
65
src/main.rs
|
@ -194,70 +194,6 @@ struct PollChoiceResponse {
|
|||
votes: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
struct PollResponse {
|
||||
title: String,
|
||||
choices: Vec<PollChoiceResponse>,
|
||||
}
|
||||
|
||||
async fn view_current_poll(State(state): State<AppState>) -> 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::<PollsConfig>(&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))
|
||||
|
|
Loading…
Add table
Reference in a new issue