From 24388ba81515c57e812994fdb9147e6de7f3a5b6 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Wed, 21 Aug 2024 12:38:20 +0200 Subject: Reformat types mod --- src/graphql/query.rs | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) (limited to 'src/graphql/query.rs') diff --git a/src/graphql/query.rs b/src/graphql/query.rs index 26f9a6e..ed83a9f 100644 --- a/src/graphql/query.rs +++ b/src/graphql/query.rs @@ -1,4 +1,4 @@ -use crate::{graphql::types::User, state::AppState}; +use crate::graphql::types::user; use async_graphql::{Context, Object}; pub struct Query; @@ -10,25 +10,7 @@ impl Query { } /// Returns all the users - async fn users<'ctx>(&self, ctx: &Context<'ctx>) -> Result>, String> { - let state = ctx.data::().expect("Can't connect to db"); - let client = &*state.client; - - let rows = client - .query("SELECT id, email, password, is_admin FROM users", &[]) - .await - .unwrap(); - - let users: Vec = rows - .iter() - .map(|row| User { - id: row.get("id"), - email: row.get("email"), - password: row.get("password"), - is_admin: row.get("is_admin"), - }) - .collect(); - - Ok(Some(users)) + async fn users<'ctx>(&self, ctx: &Context<'ctx>) -> Result>, String> { + user::get_users(ctx).await } } -- cgit v1.2.3-18-g5258