From 0bd56db0cd75cec74b960b5f14d65760d96e03ba Mon Sep 17 00:00:00 2001 From: Lennart Date: Fri, 19 Jan 2024 02:30:10 +0200 Subject: [PATCH] fix(platform): search query (#196) Fixes search queries. I forgot to test them when reviewing the sqlx refactor pr. --- platform/api/src/api/v1/gql/queries/mod.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/platform/api/src/api/v1/gql/queries/mod.rs b/platform/api/src/api/v1/gql/queries/mod.rs index e354e31a..91687253 100644 --- a/platform/api/src/api/v1/gql/queries/mod.rs +++ b/platform/api/src/api/v1/gql/queries/mod.rs @@ -31,7 +31,8 @@ impl Default for Query { #[derive(FromRow)] struct SearchResultQueryResponse { - r#type: i64, + #[from_row(rename = "type")] + ty: i64, id: Ulid, similarity: f64, total_count: i64, @@ -43,8 +44,8 @@ impl Query { &self, ctx: &Context<'_>, #[graphql(desc = "The search query.")] query: String, - #[graphql(desc = "The result limit, default: 5", validator(minimum = 0, maximum = 50))] limit: Option, - #[graphql(desc = "The result offset, default: 0", validator(minimum = 0, maximum = 950))] offset: Option, + #[graphql(desc = "The result limit, default: 5", validator(minimum = 0, maximum = 50))] limit: Option, + #[graphql(desc = "The result offset, default: 0", validator(minimum = 0, maximum = 950))] offset: Option, ) -> Result> { let global = ctx.get_global::(); @@ -92,7 +93,7 @@ impl Query { let total_count = query_results.first().map(|r| r.total_count).unwrap_or(0) as u32; let (users, categories) = query_results.iter().fold((Vec::new(), Vec::new()), |mut store, item| { - match item.r#type { + match item.ty { 0 => &mut store.0, 1 => &mut store.1, _ => unreachable!(), @@ -111,7 +112,7 @@ impl Query { let results = query_results .iter() .filter_map(|r| { - let object = match r.r#type { + let object = match r.ty { 0 => SearchAllResultData::User(Box::new(User::from(users.get(&r.id)?.clone()))), 1 => SearchAllResultData::Category(categories.get(&r.id)?.clone().into()), _ => unreachable!(),