diff --git a/server-api/db/src/messages.rs b/server-api/db/src/messages.rs index c4b8e65..de0e3f0 100644 --- a/server-api/db/src/messages.rs +++ b/server-api/db/src/messages.rs @@ -9,11 +9,6 @@ use crate::{UBigInt, BigInt, VarChar}; use crate::common::{FromDB}; -macro_rules! msg_channel { - $(value:expr) => { - format!("messages_{}", value) - } -} #[allow(dead_code)] pub struct Message { pub id: UBigInt, @@ -84,20 +79,3 @@ impl FromDB for Message { return Response::Other(no_conn!("Message::FromDB::update")) } } -impl Message { - async fn add(p: &Pool, author_id: UBigInt, content: VarChar, channel_id: UBigInt) -> Response { - //! Adds a user message to the given channel via channel_id - let conn = p.get_conn().await; - if conn.is_err() { - return Response::Other(no_conn!("Message::add")); - } - // generate the channel name - let fq_channel_id = msg_channel!(channel_id); - conn.prep_exec( - "INSERT INTO :table (id, time, content, author_id)", - params!{"cid" => fq_channel_id} - ); - return Response::Success; - } -} - diff --git a/server-api/src/common.rs b/server-api/src/common.rs deleted file mode 100644 index 72f6780..0000000 --- a/server-api/src/common.rs +++ /dev/null @@ -1,38 +0,0 @@ -use mysql_async::error::ServerError; -use hyper::{Body, Response, StatusCode}; -use serde::Serialize; -use serde_json::to_string as json; - -#[derive(Serialize)] -struct GenericErrData { - status: u16, - message: &'static str, - note: &'static str, -} - - -pub fn db_err_response_body(response: &mut Response, err: ServerError) { - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - match err.code { - // Duplicate unique value was (tried to be) inserted - 1062 => { - - let s = json(&GenericErrData { - status: 1062, - message: "Duplicate key was inserted and failed", - note: "Check parameters given" - }).unwrap(); - *response.body_mut() = Body::from(s); - }, - // Generic errors - _ => { - let s = json(&GenericErrData{ - status: 500, - message: "Generic Backend error", - note:"" - }).unwrap(); - *response.body_mut() = Body::from(s); - } - } -} - diff --git a/server-api/src/main.rs b/server-api/src/main.rs index 8c9117f..bdc905a 100644 --- a/server-api/src/main.rs +++ b/server-api/src/main.rs @@ -36,7 +36,6 @@ mod admin; mod http_params; mod db_types; -mod common; mod testing; const NO_ERR: u16 = 0;