23 lines
912 B
Rust
23 lines
912 B
Rust
use hyper::{Response, Body, StatusCode};
|
|
use hyper::header::HeaderValue;
|
|
use mysql_async::Pool;
|
|
|
|
use db::member::STATUS_ONLINE;
|
|
use db::common::FromDB;
|
|
|
|
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 db::channels::Channel::filter(p, STATUS_ONLINE).await {
|
|
db::Response::Set(users) => {
|
|
response.headers_mut().insert("Content-Type",
|
|
HeaderValue::from_static("application/json"));
|
|
|
|
*response.body_mut() = Body::from(serde_json::to_string(&users).unwrap_or("[]".into()));
|
|
},
|
|
db::Response::Other(_msg) => *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR,
|
|
_ => *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR
|
|
}
|
|
}
|