* Db::Messages::get_time_range now handles case where
start_time >= end_time Which means we won't get weird requests from clients anymore(hopefully) * Route handler for /message/time_range now handles db::Response::RestrictedInput Responds with a simple 400 and nothing else
This commit is contained in:
@@ -34,19 +34,20 @@ pub async fn get_by_time(pool: &Pool, response: &mut Response<Body>, params: Val
|
||||
match (channel, start_time, end_time) {
|
||||
(Some(channel), Some(start), Some(end)) => {
|
||||
match Message::get_time_range(pool, channel, start, end).await {
|
||||
Ok(data) => {
|
||||
response.headers_mut().insert(
|
||||
"Content-Type",
|
||||
HeaderValue::from_static("application/json"));
|
||||
|
||||
let msg_vec = match data {
|
||||
db::Response::Set(data) => data,
|
||||
_ => Vec::new()
|
||||
Ok(db_response) => {
|
||||
match db_response {
|
||||
db::Response::Set(messages) => {
|
||||
response.headers_mut().insert(
|
||||
"Content-Type",
|
||||
HeaderValue::from_static("application/json"));
|
||||
let payload = json!({"messages": messages});
|
||||
*response.body_mut() = Body::from(payload.to_string());
|
||||
},
|
||||
db::Response::RestrictedInput(_/*error message to log*/) => *response.status_mut() = StatusCode::BAD_REQUEST,
|
||||
_ => *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR
|
||||
};
|
||||
// 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());
|
||||
},
|
||||
Err(e) => {
|
||||
eprintln!("{}", e);
|
||||
|
||||
Reference in New Issue
Block a user