[C++][Pistache] Fixed #2643 (#2653)

* Fixed #2643

Refactored to/from json functions to use universal object serialization method.

* Code review found incorrect indenting and I forgot to remove unused mustache files.

* Removed helpers class because it is not needed anymore.

* Removed helpers package from docs.

* Reverted helper class removal.
This commit is contained in:
SalDiAngelus
2019-04-19 08:00:12 -04:00
committed by sunn
parent cce35d75a4
commit 89eb603c17
37 changed files with 266 additions and 932 deletions

View File

@@ -49,14 +49,11 @@ void UserApi::create_user_handler(const Pistache::Rest::Request &request, Pistac
// Getting the body param
User user;
User body;
try {
nlohmann::json request_body = nlohmann::json::parse(request.body());
user.fromJson(request_body);
this->create_user(user, response);
nlohmann::json::parse(request.body()).get_to(body);
this->create_user(body, response);
} catch (std::runtime_error & e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
@@ -67,12 +64,11 @@ void UserApi::create_user_handler(const Pistache::Rest::Request &request, Pistac
void UserApi::create_users_with_array_input_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
// Getting the body param
std::vector<User> user;
std::vector<User> body;
try {
nlohmann::json request_body = nlohmann::json::parse(request.body());
user = ArrayHelper::fromJson<User>(request_body);
this->create_users_with_array_input(user, response);
nlohmann::json::parse(request.body()).get_to(body);
this->create_users_with_array_input(body, response);
} catch (std::runtime_error & e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
@@ -83,12 +79,11 @@ void UserApi::create_users_with_array_input_handler(const Pistache::Rest::Reques
void UserApi::create_users_with_list_input_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
// Getting the body param
std::vector<User> user;
std::vector<User> body;
try {
nlohmann::json request_body = nlohmann::json::parse(request.body());
user = ArrayHelper::fromJson<User>(request_body);
this->create_users_with_list_input(user, response);
nlohmann::json::parse(request.body()).get_to(body);
this->create_users_with_list_input(body, response);
} catch (std::runtime_error & e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
@@ -168,14 +163,11 @@ void UserApi::update_user_handler(const Pistache::Rest::Request &request, Pistac
// Getting the body param
User user;
User body;
try {
nlohmann::json request_body = nlohmann::json::parse(request.body());
user.fromJson(request_body);
this->update_user(username, user, response);
nlohmann::json::parse(request.body()).get_to(body);
this->update_user(username, body, response);
} catch (std::runtime_error & e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());