+ db-lib::Channel::get added and Returns a Result<Option<Channel>> for simplicity

This is really only for check if a particular channel exists for /messages/recent's backend

* Flattening db-lib::Message::last_n
SHould make code more readable as it now has a more linear flow

* api::Messages::recent_messages now 404's when a channel that doesn't exist is request
This commit is contained in:
shockrah
2021-04-21 21:33:30 -07:00
parent 432e94054f
commit 9ab9cdb176
3 changed files with 39 additions and 16 deletions

View File

@@ -145,6 +145,9 @@ pub async fn recent_messages(pool: &Pool, response: &mut Response<Body>, params:
// 200
db::Response::Set(messages) =>
set_json_body(response, json!({"messages": messages})),
// 404 - assuming the request channel does not exist
db::Response::Empty =>
*response.status_mut() = StatusCode::NOT_FOUND,
// 400
db::Response::RestrictedInput(msg) => {
*response.status_mut() = StatusCode::BAD_REQUEST;