messaging module ready to start testing send functionalities
This commit is contained in:
parent
32c8619d93
commit
3b0b79c525
51
server/src/messages.rs
Normal file
51
server/src/messages.rs
Normal file
@ -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<Body>, params: &HashMap<&str, &str>) {
|
||||
match parse_send_params(params, vec!["content", "id"]) {
|
||||
MsgParam::Good => {},
|
||||
MsgParam::Empty => {}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user