From ec30e80ac171dba95720f054edc25adb9b74c9ef Mon Sep 17 00:00:00 2001 From: shockrah Date: Wed, 4 Nov 2020 00:33:35 -0800 Subject: [PATCH] Invites::filter 1st pass implementation ! untested --- server-api/db/src/invites.rs | 30 ++++++++++++++++++++++++++++-- server-api/db/src/lib.rs | 1 + 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/server-api/db/src/invites.rs b/server-api/db/src/invites.rs index 5b854e5..b64d58a 100644 --- a/server-api/db/src/invites.rs +++ b/server-api/db/src/invites.rs @@ -6,7 +6,7 @@ use async_trait::async_trait; use crate::{UBigInt, BigInt}; use crate::common::FromDB; -use crate::Response; +use crate::{Response, no_conn}; #[allow(dead_code)] pub struct Invite { @@ -16,7 +16,7 @@ pub struct Invite { } #[async_trait] -impl FromDB for Invite { +impl FromDB for Invite { type Row = Option<(BigInt, Option, bool)>; async fn get(p: &Pool, id: UBigInt) -> Response { @@ -84,4 +84,30 @@ impl FromDB for Invite { } return Response::Success; } + async fn filter(p: &Pool, expirey_flag: bool) -> Response { + if let Ok(conn) = p.get_conn().await { + let q = "SELECT id, uses, expires FROM invites WHERE expires = :exp"; + if let Ok(query) = conn.prep_exec(q, params!{"exp" => expirey_flag}).await { + let mapping_r = query.map_and_drop(|row| { + let (id, uses): (BigInt, Option) = mysql_async::from_row(row); + Invite { + id: id, + uses: uses, + expires: expirey_flag + } + }).await; + return match mapping_r { + Ok((_, invites)) => Response::Set(invites), + Err(_) => Response::Empty + } + } + else { + return Response::Other(no_conn!("db::Invite::filter")); + } + } + else { + return Response::Other(no_conn!("db::Invites::filter")); + } + } } + diff --git a/server-api/db/src/lib.rs b/server-api/db/src/lib.rs index a8b0857..914b576 100644 --- a/server-api/db/src/lib.rs +++ b/server-api/db/src/lib.rs @@ -1,3 +1,4 @@ +extern crate serde; pub mod member; pub mod common; pub mod invites;