Merge commit. api/resources/node.hpp speedy/rapidjson_middleware.hpp conflicts resolved

This commit is contained in:
Marko Budiselic 2015-10-17 19:34:00 +02:00
commit ebb47f0f74
5 changed files with 33 additions and 20 deletions

View File

@ -34,15 +34,18 @@ public:
//
auto node = atom->first();
// the json body is parsed (req.json)
// TODO store the properties in the
// TODO: req.json can be empty
// probably there is some other place to handle
// emptiness of req.json
// first version
//
// for(key, value in body)
// node->properties[key] = value;
// TODO parse json body and put into the node
for(auto it = req.json.MemberBegin(); it != req.json.MemberEnd(); ++it)
{
node->properties.emplace<String>(it->name.GetString(), it->value.GetString());
}
// commit the transaction
db->tx_engine.commit(t);

View File

@ -50,6 +50,9 @@ void Response<Req, Res>::send(const std::string& body)
if(!conn.keep_alive)
conn.close();
conn.request.headers.clear();
conn.request.body.clear();
conn.response.status = Status::Ok;
conn.response.buffer.clear();
conn.response.headers.clear();

View File

@ -18,14 +18,18 @@ bool rapidjson_middleware(sp::Request& req, sp::Response& res)
if (req.body.empty())
return true;
if (req.json.Parse(req.body.c_str()).HasParseError()) {
auto errorCode = rapidjson::GetParseError_En(req.json.GetParseError());
std::string parseError = "JSON parse error: " + std::string(errorCode);
res.send(http::Status::BadRequest, parseError);
return false;
}
// the body is successfuly parsed
if(!req.json.Parse(req.body.c_str()).HasParseError())
return true;
// some kind of parse error occurred
// return the error message to the client
auto error_str = rapidjson::GetParseError_En(req.json.GetParseError());
std::string parse_error = "JSON parse error: " + std::string(error_str);
res.send(http::Status::BadRequest, parse_error);
// stop further execution
return false;
}
}

View File

@ -38,7 +38,7 @@ public:
use(rapidjson_middleware);
}
Speedy(Speedy&) = delete;
Speedy(const Speedy&) = delete;
Speedy(Speedy&&) = delete;
void use(Middlewares::middleware_cb_t cb)
@ -71,6 +71,14 @@ public:
router.compile();
server.listen(ip, [this](Request& req, Response& res) {
auto route = router.match(R3::to_r3_method(req.method), req.url);
if(!route.exists())
return res.send(http::Status::NotFound, "Resource not found");
// parse url params
route.populate(req);
// run middlewares
auto result = middlewares.run(req, res);
@ -78,12 +86,6 @@ public:
if(!result)
return;
auto route = router.match(R3::to_r3_method(req.method), req.url);
if(!route.exists())
return res.send(http::Status::NotFound, "Resource not found");
route.populate(req);
route(req, res);
});
}

View File

@ -2,6 +2,7 @@
#define MEMGRAPH_STORAGE_MODEL_PROPERTIES_PROPERTIES_HPP
#include <map>
#include "rapidjson/document.h"
#include "property.hpp"