Skip to content

Commit

Permalink
fix(Backlog): properly handle non-string value matches when filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
GNMoseke committed Apr 25, 2024
1 parent f8138ad commit c1a9240
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::backlog::{BacklogItem, BacklogStore, MongoBacklogStore};
extern crate rocket;
use apod::{ApodStore, MongoApodStore};
use log::{error, info};
use mongodb::bson::Document;
use mongodb::{bson::doc, options::ClientOptions, Client};
use rocket::serde::json::{json, Json, Value};
use rocket::State;
Expand All @@ -30,8 +31,12 @@ async fn list_backlog_entries(
db: &State<MongoStores>,
) -> Json<Vec<BacklogItem>> {
// if we're given both parts of a filter, use it. Otherwise pass None.
let document_matcher = match (filter_field, filter_value) {
(Some(field), Some(val)) => doc! { field: val }.into(),
let document_matcher: Option<Document> = match (filter_field, filter_value) {
(Some(field), Some(val)) => match field {
"rating" => doc! { field: val.parse::<i32>().unwrap_or(0) }.into(),
"favorite" | "replay" => doc! { field: val.parse::<bool>().unwrap_or(false) }.into(),
_ => doc! { field: val }.into(),
},
_ => None,
};

Expand Down

0 comments on commit c1a9240

Please sign in to comment.