channel deletion seems to pass basic unit tests
This commit is contained in:
parent
362eb53650
commit
34a04f7887
@ -162,9 +162,10 @@ fn parse_insert_channel_params(name_r: Option<&Value>, kind_r: Option<&Value>) -
|
|||||||
(Some(name), Some(kind)) => {
|
(Some(name), Some(kind)) => {
|
||||||
|
|
||||||
let channel = InsertableChannel {
|
let channel = InsertableChannel {
|
||||||
name: name.to_string(),
|
name: name.as_str().unwrap().into(), // as_str removes the quotes from the output
|
||||||
kind: ChannelType::from_i64_opt(kind.as_i64()),
|
kind: ChannelType::from_i64_opt(kind.as_i64()),
|
||||||
};
|
};
|
||||||
|
println!("Insertable channel name: {}", channel.name);
|
||||||
Ok(channel)
|
Ok(channel)
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
@ -177,7 +178,7 @@ async fn insert_channel(pool: &Pool, channel: InsertableChannel) -> Result<(), D
|
|||||||
if let Ok(conn) = pool.get_conn().await {
|
if let Ok(conn) = pool.get_conn().await {
|
||||||
let db_result: Result<Conn, Error> = conn.drop_exec(
|
let db_result: Result<Conn, Error> = conn.drop_exec(
|
||||||
"INSERT INTO channels (name, kind) VALUES (:name, 0)",
|
"INSERT INTO channels (name, kind) VALUES (:name, 0)",
|
||||||
mysql_async::params!{ "name" => channel.name }
|
params!{"name" => channel.name}
|
||||||
).await;
|
).await;
|
||||||
match db_result {
|
match db_result {
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
@ -221,11 +222,10 @@ pub async fn create_channel(pool: &Pool, response: &mut Response<Body>, params:
|
|||||||
|
|
||||||
async fn db_delete_channel(pool: &Pool, name: &Value) -> Result<(), Error> {
|
async fn db_delete_channel(pool: &Pool, name: &Value) -> Result<(), Error> {
|
||||||
let conn = pool.get_conn().await?;
|
let conn = pool.get_conn().await?;
|
||||||
let q = "DELETE FROM channels WHERE name = :name";
|
conn.prep_exec(r"DELETE FROM channels WHERE name = :name", params!{"name" => name.as_str().unwrap()}).await?;
|
||||||
let p = params!{ "name" => name.as_str().unwrap() };
|
|
||||||
conn.batch_exec(q, p).await?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete_channel(pool: &Pool, response: &mut Response<Body>, params: Value) {
|
pub async fn delete_channel(pool: &Pool, response: &mut Response<Body>, params: Value) {
|
||||||
// make sure we have the right parameters provided
|
// make sure we have the right parameters provided
|
||||||
if let Some(name) = params.get("name") {
|
if let Some(name) = params.get("name") {
|
||||||
|
Loading…
Reference in New Issue
Block a user