#include "TestController.h" #include "Core/LogManager.h" #include #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 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; }