new delete_channel endpoint handler
* to be tested
This commit is contained in:
parent
3824546bba
commit
7a093c1fbc
@ -7,8 +7,11 @@ use mysql_async::prelude::{params, Queryable};
|
||||
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::db_types::{UBigInt, VarChar, Integer};
|
||||
use crate::common;
|
||||
use db::{
|
||||
self,
|
||||
UBigInt, VarChar, Integer,
|
||||
common::FromDB
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ChannelType {
|
||||
@ -163,18 +166,10 @@ pub async fn create_channel(pool: &Pool, response: &mut Response<Body>, params:
|
||||
match req_params {
|
||||
(Some(name), Some(desc), Some(kind)) => {
|
||||
match insert_channel(pool, name, desc, kind).await {
|
||||
// Server Errors are generally _ok_ to reveal in body I suppose
|
||||
Err(Error::Server(se)) => {
|
||||
common::db_err_response_body(response, se);
|
||||
//*response.status_mut() = StatusCode::BAD_REQUEST;
|
||||
//let b = format!("Server code: {}\nServer Message:{}", se.code, se.message);
|
||||
//*response.body_mut() = Body::from(b);
|
||||
},
|
||||
// generic errors get a 500
|
||||
Err(_) => {
|
||||
Err(e) => {
|
||||
println!("SERVER ERROR: {}", e);
|
||||
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
|
||||
}
|
||||
// Nothing to do when things go right
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
},
|
||||
@ -183,21 +178,21 @@ pub async fn create_channel(pool: &Pool, response: &mut Response<Body>, params:
|
||||
}
|
||||
}
|
||||
|
||||
async fn db_delete_channel(pool: &Pool, name: &Value) -> Result<(), Error> {
|
||||
let conn = pool.get_conn().await?;
|
||||
conn.prep_exec(r"DELETE FROM channels WHERE name = :name", params!{"name" => name.as_str().unwrap()}).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn delete_channel(pool: &Pool, response: &mut Response<Body>, params: Value) {
|
||||
// make sure we have the right parameters provided
|
||||
if let Some(name) = params.get("name") {
|
||||
match db_delete_channel(pool, name).await {
|
||||
Ok(_) => *response.status_mut() = StatusCode::OK,
|
||||
Err(e) => {
|
||||
*response.body_mut() = Body::from(format!("delete_chanel sql error :\n{}", e));
|
||||
use db::channels::Channel;
|
||||
if let Some(name) = params.get("channel_id") {
|
||||
if let Some(id) = name.as_u64() {
|
||||
// TODO: something more intelligent with the logging im ngl
|
||||
match Channel::delete(pool, id).await {
|
||||
db::Response::Success => {},
|
||||
db::Response::Other(data) => println!("\t{}", data),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
else {
|
||||
*response.status_mut() = StatusCode::BAD_REQUEST;
|
||||
}
|
||||
}
|
||||
else {
|
||||
*response.status_mut() = StatusCode::BAD_REQUEST;
|
||||
|
Loading…
Reference in New Issue
Block a user