+ /messages/get_range base route handler, ready for testing
This commit is contained in:
parent
b917483dac
commit
6ffcb7a73b
@ -60,6 +60,7 @@ async fn route_dispatcher(pool: &Pool, resp: &mut Response<Body>, meth: &Method,
|
|||||||
(DELETE, routes::CHANNELS_DELETE) => channels::delete_channel(pool, resp, params).await,
|
(DELETE, routes::CHANNELS_DELETE) => channels::delete_channel(pool, resp, params).await,
|
||||||
/* MESSAGING */
|
/* MESSAGING */
|
||||||
(POST, routes::MESSAGE_SEND) => messages::send_message(pool, resp, params).await,
|
(POST, routes::MESSAGE_SEND) => messages::send_message(pool, resp, params).await,
|
||||||
|
(GET, routes::MESSAGE_TIME_RANGE) => messages::get_by_time(pool, resp, params).await,
|
||||||
/* ADMIN */
|
/* ADMIN */
|
||||||
(POST, routes::SET_PERMS_BY_ADMIN) => admin::set_permissions(pool, resp, params).await,
|
(POST, routes::SET_PERMS_BY_ADMIN) => admin::set_permissions(pool, resp, params).await,
|
||||||
/* MEMBERS */
|
/* MEMBERS */
|
||||||
|
@ -5,6 +5,55 @@ use hyper::header::HeaderValue;
|
|||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
|
|
||||||
|
pub async fn get_by_time(pool: &Pool, response: &mut Response<Body>, params: Value) {
|
||||||
|
/*
|
||||||
|
* Has a ton of required parameters just be warned
|
||||||
|
* @channel: channel id we're looking at
|
||||||
|
* @start-time: how long ago do we start searching
|
||||||
|
* @end-time: how long ago do we stop searching
|
||||||
|
* {
|
||||||
|
* "channel": 1,
|
||||||
|
* "start-time": unix_now - 24 hours
|
||||||
|
* "end-time": unix_now - 23 hours
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
let channel = match params.get("channel") {
|
||||||
|
Some(chan_v) => chan_v.as_u64(),
|
||||||
|
None => None
|
||||||
|
};
|
||||||
|
let start_time = match params.get("start-time") {
|
||||||
|
Some(val) => val.as_i64(),
|
||||||
|
None => None
|
||||||
|
};
|
||||||
|
let end_time = match params.get("end-time") {
|
||||||
|
Some(val) => val.as_i64(),
|
||||||
|
None => None
|
||||||
|
};
|
||||||
|
use db::messages::Message;
|
||||||
|
match (channel, start_time, end_time) {
|
||||||
|
(Some(channel), Some(start), Some(end)) => {
|
||||||
|
if let Ok(data) = Message::get_time_range(pool, channel, start, end).await {
|
||||||
|
response.headers_mut().insert(
|
||||||
|
"Content-Type",
|
||||||
|
HeaderValue::from_static("application/json"));
|
||||||
|
|
||||||
|
let msg_vec = match data {
|
||||||
|
db::Response::Set(data) => data,
|
||||||
|
_ => Vec::new()
|
||||||
|
};
|
||||||
|
// this absolute lack of data streaming is prolly gonna suck like
|
||||||
|
// a whoe in hell week for performance but lets pretend servers don't get massive
|
||||||
|
let payload = json!({"messages": msg_vec});
|
||||||
|
*response.body_mut() = Body::from(payload.to_string());
|
||||||
|
} else {
|
||||||
|
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => *response.status_mut() = StatusCode::BAD_REQUEST
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn send_message(pool: &Pool, response: &mut Response<Body>, params: Value) {
|
pub async fn send_message(pool: &Pool, response: &mut Response<Body>, params: Value) {
|
||||||
/*
|
/*
|
||||||
* @content: expecting string type
|
* @content: expecting string type
|
||||||
|
@ -11,6 +11,7 @@ pub const CHANNELS_CREATE: Rstr = "/channels/create"; // requires @name @kind
|
|||||||
pub const CHANNELS_DELETE: Rstr = "/channels/delete"; // requires @name perms::DELETE_CHANNEL
|
pub const CHANNELS_DELETE: Rstr = "/channels/delete"; // requires @name perms::DELETE_CHANNEL
|
||||||
|
|
||||||
pub const MESSAGE_SEND: Rstr = "/message/send"; // requires @content perms::MESSAGE_SEND
|
pub const MESSAGE_SEND: Rstr = "/message/send"; // requires @content perms::MESSAGE_SEND
|
||||||
|
pub const MESSAGE_TIME_RANGE: Rstr = "/message/get_range"; // requires @channel(id) @start-time @end-time
|
||||||
|
|
||||||
pub const GET_ONLINE_MEMBERS: Rstr = "/members/get_online";
|
pub const GET_ONLINE_MEMBERS: Rstr = "/members/get_online";
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user