Invites::filter 1st pass implementation

! untested
This commit is contained in:
shockrah 2020-11-04 00:33:35 -08:00
parent 84f04c20cd
commit ec30e80ac1
2 changed files with 29 additions and 2 deletions

View File

@ -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<Invite> for Invite {
impl FromDB<Invite, bool> for Invite {
type Row = Option<(BigInt, Option<BigInt>, bool)>;
async fn get(p: &Pool, id: UBigInt) -> Response<Self> {
@ -84,4 +84,30 @@ impl FromDB<Invite> for Invite {
}
return Response::Success;
}
async fn filter(p: &Pool, expirey_flag: bool) -> Response<Self> {
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<BigInt>) = 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"));
}
}
}

View File

@ -1,3 +1,4 @@
extern crate serde;
pub mod member;
pub mod common;
pub mod invites;