diff --git a/json-api/src/main.rs b/json-api/src/main.rs index eeeaf04..634790f 100644 --- a/json-api/src/main.rs +++ b/json-api/src/main.rs @@ -12,6 +12,7 @@ extern crate jsonwebtoken; use std::net::SocketAddr; use std::convert::Infallible; // our main dispatcher basically never fails hence why we use this use std::env::{self, set_var}; +use std::collections::HashMap; use tokio; use hyper::{ @@ -45,8 +46,14 @@ const NO_ERR: u16 = 0; const CONFIG_ERR: u16 = 1; const SHUTDOWN_ERR: u16 = 2; -async fn route_dispatcher(pool: &Pool, resp: &mut Response
, meth: &Method, path: &str, params: serde_json::Value) { - // At some point we should have some way of hiding this obnoxious complexity +async fn route_dispatcher( + pool: &Pool, + resp: &mut Response, + meth: &Method, + path: &str, + body: Body, + params: HashMap<&str, &str>) { + const GET: &Method = &Method::GET; const POST: &Method = &Method::POST; const DELETE: &Method = &Method::DELETE; @@ -59,7 +66,7 @@ async fn route_dispatcher(pool: &Pool, resp: &mut Response, meth: &Method, (POST, routes::CHANNELS_CREATE) => channels::create_channel(pool, resp, params).await, (DELETE, routes::CHANNELS_DELETE) => channels::delete_channel(pool, resp, params).await, /* MESSAGING */ - (POST, routes::MESSAGE_SEND) => messages::send_message(pool, resp, params).await, + (POST, routes::MESSAGE_SEND) => messages::send_message(pool, resp, body, params).await, (GET, routes::MESSAGE_TIME_RANGE) => messages::get_by_time(pool, resp, params).await, (GET, routes::MESSAGE_FROM_ID) =>messages::from_id(pool, resp, params).await, /* ADMIN */ @@ -81,16 +88,20 @@ async fn main_responder(request: Request) -> Result