Checking for valid channel.kind
on /channels/create
This commit is contained in:
parent
8e2b52d1c9
commit
201297f4c1
@ -49,21 +49,27 @@ pub async fn create_channel(pool: &Pool, response: &mut Response<Body>, params:
|
|||||||
|
|
||||||
match req_params {
|
match req_params {
|
||||||
(Some(name), Some(desc), Some(kind)) => {
|
(Some(name), Some(desc), Some(kind)) => {
|
||||||
// Send the data up to the db, then return the new channel back to the user(?)
|
use db::channels::{TEXT_CHANNEL, VOICE_CHANNEL};
|
||||||
match db::channels::Channel::add(pool, name, desc, kind.try_into().unwrap()).await {
|
if kind < VOICE_CHANNEL as i64 || kind > TEXT_CHANNEL as i64 {
|
||||||
db::Response::Row(row) => {
|
*response.status_mut() = StatusCode::BAD_REQUEST; // restriciting to 1|2 for valid channel kinds
|
||||||
response.headers_mut().insert("Content-Type",
|
}
|
||||||
HeaderValue::from_static("application/json"));
|
else {
|
||||||
|
// Send the data up to the db, then return the new channel back to the user(?)
|
||||||
*response.body_mut() = Body::from(to_string(&row).unwrap_or("{}".into()));
|
match db::channels::Channel::add(pool, name, desc, kind.try_into().unwrap()).await {
|
||||||
},
|
db::Response::Row(row) => {
|
||||||
db::Response::Empty => *response.status_mut() = StatusCode::NOT_FOUND,
|
response.headers_mut().insert("Content-Type",
|
||||||
// TODO: loggin
|
HeaderValue::from_static("application/json"));
|
||||||
db::Response::Other(msg) => {
|
|
||||||
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
|
*response.body_mut() = Body::from(to_string(&row).unwrap_or("{}".into()));
|
||||||
eprintln!("\t{}", msg);
|
},
|
||||||
|
db::Response::Empty => *response.status_mut() = StatusCode::NOT_FOUND,
|
||||||
|
// TODO: loggin
|
||||||
|
db::Response::Other(msg) => {
|
||||||
|
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
|
||||||
|
eprintln!("\t{}", msg);
|
||||||
|
}
|
||||||
|
_ => *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR
|
||||||
}
|
}
|
||||||
_ => *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// basically one of the parameter gets failed so we bail on all of this
|
// basically one of the parameter gets failed so we bail on all of this
|
||||||
|
Loading…
Reference in New Issue
Block a user