You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
#include "TestController.h"
|
|
|
|
#include "Core/LogManager.h"
|
|
|
|
#include <QMap>
|
|
|
|
|
|
|
|
#include "Repository/UserRepository.h"
|
|
|
|
|
|
|
|
TestController::TestController() {}
|
|
|
|
|
|
|
|
int TestController::get(HttpRequest *req, HttpResponse *resp)
|
|
|
|
{
|
|
|
|
auto id = req->query_params["id"];
|
|
|
|
auto user = UserRepository::findById(QString::fromStdString(id).toLong());
|
|
|
|
resp->json["id"] = user->id;
|
|
|
|
resp->json["username"] = user->username.toStdString();
|
|
|
|
return HTTP_STATUS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TestController::post(HttpRequest *req, HttpResponse *resp)
|
|
|
|
{
|
|
|
|
nlohmann::json data = nlohmann::json::parse(req->body.c_str());
|
|
|
|
QMap<std::string, std::string> map;
|
|
|
|
map.insert("code", "200");
|
|
|
|
map.insert("msg", "this is a json demo !");
|
|
|
|
return resp->Json(map.toStdMap());
|
|
|
|
}
|
|
|
|
|
|
|
|
int TestController::put(HttpRequest *req, HttpResponse *resp)
|
|
|
|
{
|
|
|
|
resp->json["code"] = 200;
|
|
|
|
resp->json["params1"] = req->query_params["params1"];
|
|
|
|
return HTTP_STATUS_OK;
|
|
|
|
}
|