diff --git a/server-api/db/src/channels.rs b/server-api/db/src/channels.rs index 8842dd7..9ff7a5b 100644 --- a/server-api/db/src/channels.rs +++ b/server-api/db/src/channels.rs @@ -64,15 +64,16 @@ impl FromDB for Channel { } async fn delete(p: &Pool, id: UBigInt) -> Response { - if let Ok(conn) = p.get_conn().await { - let q = "DELETE FROM channels WHERE id = :id"; - let result: Result = - conn.drop_exec(q, params!{"id" => id}).await; - return match result { - Ok(_) => Response::Success, - Err(_) => Response::Other(sql_err!("Member::FromDB::delete Listen i dont know either")) - } + let conn = p.get_conn().await; + if conn.is_err() { + return Response::Other(no_conn!("Member::FromDB::delete")) + } + + // TODO: do something with the return values where possible + return match conn.unwrap().prep_exec("DELETE FROM CHANNELS WHERE id = :id", params!{"id" => id}).await { + Ok(_) => Response::Success, + Err(_) => Response::Other(sql_err!("Channels::FromDB::delete")) } - return Response::Other(no_conn!("Member::FromDB::delete")) } } + diff --git a/server-api/migrations/2020-03-11-005217_channels/up.sql b/server-api/migrations/2020-03-11-005217_channels/up.sql index c5ca788..ccc7987 100644 --- a/server-api/migrations/2020-03-11-005217_channels/up.sql +++ b/server-api/migrations/2020-03-11-005217_channels/up.sql @@ -1,7 +1,7 @@ CREATE TABLE IF NOT EXISTS `channels` ( `id` BIGINT UNSIGNED NOT NULL auto_increment, `name` UNIQUE VARCHAR(255) NOT NULL, - `description` VARCHAR(1024), + `description` VARCHAR(4096), `kind` INTEGER NOT NULL, PRIMARY KEY(`id`), UNIQUE KEY(`name`) ); diff --git a/server-api/migrations/2020-07-06-022319_messages/up.sql b/server-api/migrations/2020-07-06-022319_messages/up.sql index 29286b0..661a932 100644 --- a/server-api/migrations/2020-07-06-022319_messages/up.sql +++ b/server-api/migrations/2020-07-06-022319_messages/up.sql @@ -4,8 +4,6 @@ CREATE TABLE IF NOT EXISTS `messages`( `time` BIGINT NOT NULL, `content` VARCHAR(2048) NOT NULL, `author_id` BIGINT UNSIGNED NOT NULL, - `channel_name` VARCHAR(255) NOT NULL, PRIMARY KEY (`id`), - FOREIGN KEY (`author_id`) REFERENCES members(`id`), - FOREIGN KEY (`channel_name`) REFERENCES channels(`name`) + FOREIGN KEY (`author_id`) REFERENCES members(`id`) ON DELETE CASCADE ); diff --git a/server-api/src/routes.rs b/server-api/src/routes.rs index e3acc45..4d0129a 100644 --- a/server-api/src/routes.rs +++ b/server-api/src/routes.rs @@ -3,7 +3,7 @@ pub const INVITE_CREATE: &'static str = "/invite/create"; // requires none pub const CHANNELS_LIST: &'static str = "/channels/list"; // requires none pub const CHANNELS_CREATE: &'static str = "/channels/create"; // requires @name @kind -pub const CHANNELS_DELETE: &'static str = "/channels/delete"; // requires @name +pub const CHANNELS_DELETE: &'static str = "/channels/delete"; // requires @channel_id pub const MESSAGE_SEND: &'static str = "/message/send"; // requires @content