1st pass implementation of the new .filter implementation
! Totally untested so far and WILL have to go through a battery of tests before I'm confident with this
This commit is contained in:
parent
8ce88faa78
commit
562377d6e2
@ -9,7 +9,6 @@ use crate::{UBigInt, BigInt, Integer, VarChar};
|
|||||||
|
|
||||||
use crate::common::{FromDB};
|
use crate::common::{FromDB};
|
||||||
|
|
||||||
#[allow(dead_code)] // only because some fields are read by the user
|
|
||||||
pub struct Member {
|
pub struct Member {
|
||||||
pub id: UBigInt,
|
pub id: UBigInt,
|
||||||
pub secret: VarChar,
|
pub secret: VarChar,
|
||||||
@ -19,6 +18,11 @@ pub struct Member {
|
|||||||
pub permissions: UBigInt,
|
pub permissions: UBigInt,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub const STATUS_ONLINE: Integer = 0;
|
||||||
|
pub const STATUS_OFFLINE: Integer = 1;
|
||||||
|
pub const STATUS_AWAY: Integer = 2;
|
||||||
|
pub const STATUS_DO_NOT_DISTURB: Integer = 3;
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
* conn = getconn
|
* conn = getconn
|
||||||
@ -27,7 +31,7 @@ pub struct Member {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl FromDB<Member> for Member {
|
impl FromDB<Member, Integer> for Member {
|
||||||
type Row = Option<(VarChar, VarChar, BigInt, Integer, UBigInt)>;
|
type Row = Option<(VarChar, VarChar, BigInt, Integer, UBigInt)>;
|
||||||
|
|
||||||
async fn get(p: &Pool, id: UBigInt) -> Response<Self> {
|
async fn get(p: &Pool, id: UBigInt) -> Response<Self> {
|
||||||
@ -108,4 +112,42 @@ impl FromDB<Member> for Member {
|
|||||||
|
|
||||||
return Response::Empty;
|
return Response::Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn filter(p: &Pool, status: Integer) -> Response<Self> {
|
||||||
|
//! @params status
|
||||||
|
return match (p.get_conn().await, status) {
|
||||||
|
(Ok(conn), STATUS_ONLINE) | (Ok(conn), STATUS_OFFLINE) |
|
||||||
|
(Ok(conn), STATUS_AWAY) | (Ok(conn), STATUS_DO_NOT_DISTURB) => {
|
||||||
|
// TODO: Allow people to query somewhere in the middle of this set
|
||||||
|
// i.e. we should be able to get user 100 -> 150 instead of just the
|
||||||
|
// first 1000 people
|
||||||
|
let q =
|
||||||
|
"SELECT id, name, status, permissions FROM memebrs
|
||||||
|
WHERE status = :stat LIMIT 1000"; // high limit for now
|
||||||
|
if let Ok(query) = conn.prep_exec(q, params!{"stat" => status}).await {
|
||||||
|
let mapping_r = query.map_and_drop(|row| {
|
||||||
|
let (id, name, status, permissions): (UBigInt, VarChar, Integer, UBigInt) =
|
||||||
|
mysql_async::from_row(row);
|
||||||
|
|
||||||
|
Member {
|
||||||
|
id: id,
|
||||||
|
secret: "".into(), // no show for obv reasons
|
||||||
|
name: name,
|
||||||
|
joindate: 0, // doesn't matter
|
||||||
|
status: status,
|
||||||
|
permissions: permissions
|
||||||
|
}
|
||||||
|
}).await;
|
||||||
|
match mapping_r {
|
||||||
|
Ok((_, members)) => Response::Set(members),
|
||||||
|
Err(_) => Response::Other(sql_err!("db::Members::filter"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Response::Other(sql_err!("db::Members::filter"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => Response::Other(sql_err!("err"))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user