diff --git a/server/src/messages.rs b/server/src/messages.rs new file mode 100644 index 0000000..bfdea37 --- /dev/null +++ b/server/src/messages.rs @@ -0,0 +1,51 @@ +use std::collections::HashMap; + +use mysql_async::Pool; + +use hyper::{Response, Body, StatusCode}; + +use crate::members::Member; + + +struct Message { + author: Member, + date: u64, + content: String +} + +enum MsgParam { + Good, + Empty +} +impl MsgParam { + fn is_good(&self) -> bool { + match self { + Good => true, + _ => false + } + } + + fn is_empty(&self) -> bool { + match self { + Empty => true, + _ => false, + } + } +} + +fn parse_send_params(p: &HashMap<&str, &str>, keys: Vec<&str>) -> MsgParam { + let mut cond = MsgParam::Good; + for k in keys.iter() { + if !p.contains_key(k) { + cond = MsgParam::Empty; + } + } + cond +} + +pub async fn send_message(pool: &Pool, response: &Response, params: &HashMap<&str, &str>) { + match parse_send_params(params, vec!["content", "id"]) { + MsgParam::Good => {}, + MsgParam::Empty => {} + } +} \ No newline at end of file