get_online_members now uses db-lib for its back end
This means we've removed a ton of old raw sql code
This commit is contained in:
parent
b966c61c20
commit
2448e1b200
@ -1,11 +1,13 @@
|
|||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use hyper::{Response, Body};
|
use hyper::{Response, Body, StatusCode};
|
||||||
|
use hyper::header::HeaderValue;
|
||||||
use mysql_async::{Conn, Pool, error::Error as SqlError};
|
use mysql_async::{Conn, Pool, error::Error as SqlError};
|
||||||
use mysql_async::prelude::{params, Queryable};
|
use mysql_async::prelude::{params, Queryable};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use db::{UBigInt, BigInt, Integer, VarChar};
|
use db::{UBigInt, BigInt, Integer, VarChar};
|
||||||
use db::member::STATUS_ONLINE;
|
use db::member::STATUS_ONLINE;
|
||||||
|
use db::common::FromDB;
|
||||||
use crate::auth;
|
use crate::auth;
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
@ -58,29 +60,19 @@ pub async fn insert_new_member(p: &Pool, name: VarChar, perms: u64) -> Result<Me
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn select_online_default(p: &Pool) -> Result<Vec<(UBigInt, VarChar)>, SqlError> {
|
|
||||||
let conn = p.get_conn().await?;
|
|
||||||
let q = format!("SELECT id, name FROM members WHERE status = {} LIMIT 100", STATUS_ONLINE);
|
|
||||||
let data = conn.prep_exec(&q, ()).await?;
|
|
||||||
let (_, users) = data.map_and_drop(|row| {
|
|
||||||
let (id, nickname): (UBigInt, VarChar) = mysql_async::from_row(row);
|
|
||||||
(id, nickname)
|
|
||||||
}).await?;
|
|
||||||
|
|
||||||
return Ok(users);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn get_online_members(p: &Pool, response: &mut Response<Body>) {
|
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
|
||||||
* Json {
|
// existance
|
||||||
* "members": [...],
|
// TODO: loggin at some point or something idklol
|
||||||
* "start": 0,
|
return match db::channels::Channel::filter(p, STATUS_ONLINE).await {
|
||||||
* "count": 100
|
db::Response::Set(users) => {
|
||||||
* }
|
response.headers_mut().insert("Content-Type",
|
||||||
*/
|
HeaderValue::from_static("application/json"));
|
||||||
if let Ok(list) = select_online_default(p).await {
|
|
||||||
// unwrap_or`ing for serde_json since it shouldn't fail in theory(on paper)
|
*response.body_mut() = Body::from(serde_json::to_string(&users).unwrap_or("[]".into()));
|
||||||
*response.body_mut() = Body::from(serde_json::to_string(&list).unwrap_or("[]".into()));
|
},
|
||||||
|
db::Response::Other(_msg) => *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
_ => *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR
|
||||||
}
|
}
|
||||||
println!("fuck bro");
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user