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.

33 lines
930 B

3 days ago
#include "TestController.h"
#include "Core/LogManager.h"
#include <QMap>
3 days ago
#include "Repository/UserRepository.h"
3 days ago
TestController::TestController() {}
int TestController::get(HttpRequest *req, HttpResponse *resp)
{
3 days ago
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;
3 days ago
}
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;
}