diff --git a/server-api/src/channels.rs b/server-api/src/channels.rs index 981184b..8f1a2ad 100644 --- a/server-api/src/channels.rs +++ b/server-api/src/channels.rs @@ -38,14 +38,29 @@ pub async fn create_channel(pool: &Pool, response: &mut Response, params: */ // Theres an extra un-needed unwrap to be cut out from this proc // specifically with the desc parameter + use std::convert::TryInto; + let req_params: (Option<&str>, Option<&str>, Option) = match (params.get("name"), params.get("description"), params.get("kind")) { (Some(name), Some(desc), Some(kind)) => (name.as_str(), desc.as_str(), kind.as_i64()), (Some(name), None, Some(kind)) => (name.as_str(), Some("No Description"), kind.as_i64()), _ => (None, None, None) }; + match req_params { (Some(name), Some(desc), Some(kind)) => { + // Send the data up to the db, then return the new channel back to the user(?) + match db::channels::Channel::add(pool, name, desc, kind.try_into().unwrap()).await { + db::Response::Row(row) => { + response.headers_mut().insert("Content type", + HeaderValue::from_static("json/application")); + + *response.body_mut() = Body::from(to_string(&row).unwrap_or("{}".into())); + }, + db::Response::Empty => {}, + db::Response::Other(msg) => {}, + _ => {*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;} + } }, // basically one of the parameter gets failed so we bail on all of this _ => *response.status_mut() = StatusCode::BAD_REQUEST