Adding new routes for /members/get_online & /members/me
Passing the previous tests as well
This commit is contained in:
@@ -72,6 +72,7 @@ async fn route_dispatcher(
|
||||
(POST, routes::SET_PERMS_BY_ADMIN) => admin::set_permissions(pool, resp, params).await,
|
||||
/* MEMBERS */
|
||||
(GET, routes::GET_ONLINE_MEMBERS) => members::get_online_members(pool, resp).await,
|
||||
(GET, routes::GET_MYSELF) => members::get_self(pool, resp, params).await,
|
||||
/* OWNER */
|
||||
(POST, routes::SET_NEW_ADMIN) => admin::new_admin(pool, resp, params).await,
|
||||
/* META ROUTE */
|
||||
|
||||
@@ -1,21 +1,48 @@
|
||||
use std::collections::HashMap;
|
||||
use hyper::{Response, Body, StatusCode};
|
||||
use mysql_async::Pool;
|
||||
use serde_json::json;
|
||||
|
||||
use db::member::STATUS_ONLINE;
|
||||
use db::common::FromDB;
|
||||
use db::member::Member;
|
||||
use db::Response::*;
|
||||
|
||||
use crate::http::set_json_body;
|
||||
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 db::channels::Channel::filter(p, STATUS_ONLINE).await {
|
||||
db::Response::Set(users) => {
|
||||
return match Member::filter(p, STATUS_ONLINE).await {
|
||||
Set(users) => {
|
||||
set_json_body(response, json!(users));
|
||||
},
|
||||
db::Response::Other(_msg) => *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
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_self(p: &Pool, response: &mut Response<Body>, params: HashMap<String, String>) {
|
||||
let uid = qs_param!(params, "id", u64).unwrap();
|
||||
|
||||
match Member::get(p, uid).await {
|
||||
Row(user) => {
|
||||
set_json_body(response, json!({
|
||||
"id" : user.id,
|
||||
"name" : user.name,
|
||||
"joindate" : user.joindate,
|
||||
"permissions" : user.permissions
|
||||
}));
|
||||
},
|
||||
Other(e) => eprintln!("{}", e),
|
||||
_ => {
|
||||
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -14,7 +14,8 @@ pub const MESSAGE_SEND: Rstr = "/message/send"; // requires @content per
|
||||
pub const MESSAGE_TIME_RANGE: Rstr = "/message/get_range"; // requires @channel(id) @start-time @end-time
|
||||
pub const MESSAGE_FROM_ID: Rstr = "/message/from_id"; // requires @channel(id) requires @start(id) @<optional>limit(1..1000)
|
||||
|
||||
pub const GET_ONLINE_MEMBERS: Rstr = "/members/get_online";
|
||||
pub const GET_ONLINE_MEMBERS: Rstr = "/members/get_online"; // requires none
|
||||
pub const GET_MYSELF: Rstr = "/members/me"; // @requires none
|
||||
|
||||
|
||||
// ADMIN ROUTES
|
||||
|
||||
Reference in New Issue
Block a user