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:
shockrah
2021-03-20 22:40:07 -07:00
parent 03c41b6833
commit 975acfd606
7 changed files with 67 additions and 32 deletions

View File

@@ -4,7 +4,7 @@ use mysql_async::Pool;
use serde_json::json;
use db::member::STATUS_ONLINE;
use db::Member;
use db::{PublicMember, Member};
use db::Response::*;
use crate::http::set_json_body;
@@ -12,19 +12,22 @@ use crate::qs_param;
pub async fn get_online_members(p: &Pool, response: &mut Response<Body>) {
// TODO: at some point we should provide a way of not querying literally every user in
// existance
// TODO: loggin at some point or something idklol
return match Member::filter(p, STATUS_ONLINE).await {
Set(users) => {
set_json_body(response, json!(users));
// Lists out the available online members at the time
// Member structs are wildly small so for most cases this query really isn't that expensive
match PublicMember::get_online(p, STATUS_ONLINE).await {
Ok(dbresponse) => {
match dbresponse {
Set(users) => set_json_body(response, json!(users)),
Other(e) => {
eprintln!("{}", e);
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
},
// Unreachable code but required for rustc to be happy
_ => *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR
};
},
db::Response::Other(e) => {
eprintln!("{}", e);
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
},
_ => *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR
}
Err(e) => eprintln!("Sql error: {}", e)
};
}
pub async fn get_self(p: &Pool, response: &mut Response<Body>, params: HashMap<String, String>) {
@@ -117,3 +120,4 @@ mod tests {
println!("Response: {:?}", resp);
}
}