Backend REST API changes:
* Fixed weird match with get_online_members + Now using special(smoll) Public Member struct for public member data fetches as. They're size on networks should be pretty small so we can package a ton of them in a single request DOCS changes: - Removing references to unix timestamps in seconds - Removing references to joindate * Exact content-type values now specified
This commit is contained in:
@@ -82,3 +82,11 @@ pub struct Member {
|
||||
pub permissions: UBigInt,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct PublicMember {
|
||||
pub id: UBigInt,
|
||||
pub name: VarChar,
|
||||
pub status: Integer,
|
||||
pub permissions: UBigInt,
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ use mysql_async::error::Error as SqlError;
|
||||
|
||||
use crate::{Response, no_conn, sql_err};
|
||||
use crate::{UBigInt, Integer, VarChar};
|
||||
use crate::Member;
|
||||
use crate::{PublicMember, Member};
|
||||
|
||||
|
||||
|
||||
@@ -152,3 +152,32 @@ impl Member {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl PublicMember {
|
||||
pub async fn get_online(p: &Pool, status: Integer) -> Result<Response<Self>, SqlError> {
|
||||
let valid_status = status == STATUS_ONLINE ||
|
||||
status == STATUS_AWAY ||
|
||||
status == STATUS_OFFLINE ||
|
||||
status == STATUS_DO_NOT_DISTURB;
|
||||
|
||||
if !valid_status {
|
||||
return Ok(Response::RestrictedInput(format!("Invalid status value")));
|
||||
} else {
|
||||
let conn = p.get_conn().await?;
|
||||
let q = "SELECT id, name, permissions FROM members
|
||||
WHERE status = :status LIMIT 1000";
|
||||
|
||||
let result = conn.prep_exec(q, params!{"status" => status}).await?;
|
||||
let (_, data): (_, Vec<PublicMember>) = result.map_and_drop(|row| {
|
||||
let (id, name, permissions): (UBigInt, VarChar, UBigInt) =
|
||||
mysql_async::from_row(row);
|
||||
|
||||
PublicMember { id, name, permissions, status }
|
||||
}).await?;
|
||||
|
||||
return Ok(Response::Set(data));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user