Updated /message/get_time to pass client api testing
This commit is contained in:
parent
c89c2a4469
commit
5c4bc6f96f
@ -157,7 +157,7 @@ impl Message {
|
||||
|
||||
pub async fn get_time_range(p: &Pool, channel_id: UBigInt, start: BigInt, end: BigInt) -> Result<Response<Self>, SqlError> {
|
||||
let conn = p.get_conn().await?;
|
||||
let q = "SELECT id, time, content, author_id WHERE channel_id = :channel AND time >= :start AND time < :end";
|
||||
let q = "SELECT id, time, content, author_id FROM messages WHERE channel_id = :channel AND time >= :start AND time < :end";
|
||||
|
||||
let select_result = conn.prep_exec(
|
||||
q, params!{
|
||||
|
@ -33,7 +33,8 @@ pub async fn get_by_time(pool: &Pool, response: &mut Response<Body>, params: Val
|
||||
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 {
|
||||
match Message::get_time_range(pool, channel, start, end).await {
|
||||
Ok(data) => {
|
||||
response.headers_mut().insert(
|
||||
"Content-Type",
|
||||
HeaderValue::from_static("application/json"));
|
||||
@ -46,9 +47,12 @@ pub async fn get_by_time(pool: &Pool, response: &mut Response<Body>, params: Val
|
||||
// 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 {
|
||||
},
|
||||
Err(e) => {
|
||||
eprintln!("{}", e);
|
||||
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
|
||||
}
|
||||
};
|
||||
},
|
||||
_ => *response.status_mut() = StatusCode::BAD_REQUEST
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user