-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAddUserProcessor.cpp
35 lines (28 loc) · 968 Bytes
/
AddUserProcessor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//
// Created by victor on 16/10/17.
//
#include "AddUserProcessor.h"
#include "usuariocontroller.h"
#include <folly/dynamic.h>
#include <folly/json.h>
#include <proxygen/httpserver/ResponseBuilder.h>
namespace cxxdoor {
AddUserProcessor::AddUserProcessor(proxygen::ResponseHandler *downstream) : CommandProcessor(downstream) {}
void AddUserProcessor::onEOM() noexcept {
auto s = _body->moveToFbString();
auto obj = folly::parseJson(s);
std::string nombre = obj["username"].asString();
std::string password = obj["password"].asString();
std::string email = obj["email"].asString();
bool res = UsuarioController::getInstance()->crearUsuario(nombre, password, email);
if (res) {
proxygen::ResponseBuilder(_downstream)
.status(201, "Created")
.sendWithEOM();
} else {
proxygen::ResponseBuilder(_downstream)
.status(500, "Error creando usuario").sendWithEOM();
}
}
AddUserProcessor::~AddUserProcessor() =default;
}