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> {
|
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 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(
|
let select_result = conn.prep_exec(
|
||||||
q, params!{
|
q, params!{
|
||||||
|
@ -33,22 +33,26 @@ pub async fn get_by_time(pool: &Pool, response: &mut Response<Body>, params: Val
|
|||||||
use db::messages::Message;
|
use db::messages::Message;
|
||||||
match (channel, start_time, end_time) {
|
match (channel, start_time, end_time) {
|
||||||
(Some(channel), Some(start), Some(end)) => {
|
(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 {
|
||||||
response.headers_mut().insert(
|
Ok(data) => {
|
||||||
"Content-Type",
|
response.headers_mut().insert(
|
||||||
HeaderValue::from_static("application/json"));
|
"Content-Type",
|
||||||
|
HeaderValue::from_static("application/json"));
|
||||||
|
|
||||||
let msg_vec = match data {
|
let msg_vec = match data {
|
||||||
db::Response::Set(data) => data,
|
db::Response::Set(data) => data,
|
||||||
_ => Vec::new()
|
_ => Vec::new()
|
||||||
};
|
};
|
||||||
// this absolute lack of data streaming is prolly gonna suck like
|
// 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
|
// a whoe in hell week for performance but lets pretend servers don't get massive
|
||||||
let payload = json!({"messages": msg_vec});
|
let payload = json!({"messages": msg_vec});
|
||||||
*response.body_mut() = Body::from(payload.to_string());
|
*response.body_mut() = Body::from(payload.to_string());
|
||||||
} else {
|
},
|
||||||
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
|
Err(e) => {
|
||||||
}
|
eprintln!("{}", e);
|
||||||
|
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
};
|
||||||
},
|
},
|
||||||
_ => *response.status_mut() = StatusCode::BAD_REQUEST
|
_ => *response.status_mut() = StatusCode::BAD_REQUEST
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user