aboutsummaryrefslogtreecommitdiff
path: root/src/routes/mod.rs
diff options
context:
space:
mode:
authorKevin J Hoerr <kjhoerr@protonmail.com>2018-08-31 19:47:09 -0400
committerKevin Hoerr <kjhoerr@submelon.tech>2018-08-31 23:24:45 -0400
commit4fb3dc1c9d6b74df77a4d56d826b8842481bb377 (patch)
tree729f93aa88f40f74bdce8414ab77209dc3b911b6 /src/routes/mod.rs
parent8ec18f34412e691356bf431b3d81ca08937a9c36 (diff)
downloadaugust-offensive-4fb3dc1c9d6b74df77a4d56d826b8842481bb377.tar.gz
august-offensive-4fb3dc1c9d6b74df77a4d56d826b8842481bb377.tar.bz2
august-offensive-4fb3dc1c9d6b74df77a4d56d826b8842481bb377.zip
Implement NotUnderstood message; Wrap messages with OutgoingMsg
Diffstat (limited to 'src/routes/mod.rs')
-rw-r--r--src/routes/mod.rs27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/routes/mod.rs b/src/routes/mod.rs
index 017413b..16fcce9 100644
--- a/src/routes/mod.rs
+++ b/src/routes/mod.rs
@@ -1,24 +1,37 @@
-use actix_web::{HttpRequest, Json, Result, Responder};
+use actix_web::{HttpRequest, Json, Result};
use std::ops::Deref;
pub mod messages;
use messages::*;
-pub fn not_understood(_req: &HttpRequest) -> impl Responder {
- "Hello, world!"
+type JsonMessage<U> = Result<Json<OutgoingMsg<U>>>;
+
+// Sends a default response message when requested an undefined resource.
+pub fn not_understood(req: &HttpRequest) -> JsonMessage<NotUnderstood> {
+ let message = NotUnderstood {
+ path: destruct_path(req.path()),
+ };
+
+ Ok(Json(message.as_outgoing()))
}
-pub fn callback(req: &HttpRequest) -> Result<Json<Callback>> {
+// Sends Callback message with information from HttpRequest.
+pub fn callback(req: &HttpRequest) -> JsonMessage<Callback> {
let path = req.path();
+ let method = req.method().as_str();
let query_ref = req.query();
let request = query_ref.deref().clone();
- Ok(Json(Callback {
+ let callback = Callback {
path: destruct_path(path),
- request: request,
- }))
+ request: String::from(method),
+ content: request,
+ };
+
+ Ok(Json(callback.as_outgoing()))
}
+// Takes an HttpRequest path and splits it into an array.
fn destruct_path(path: &str) -> Vec<String> {
path.split_terminator("/")
// first element is always blank due to link starting with "/api"