forked from janhq/cortex.cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigs.cc
More file actions
55 lines (51 loc) · 1.79 KB
/
configs.cc
File metadata and controls
55 lines (51 loc) · 1.79 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "configs.h"
#include "utils/cortex_utils.h"
void Configs::GetConfigurations(
const HttpRequestPtr& req,
std::function<void(const HttpResponsePtr&)>&& callback) const {
auto get_config_result = config_service_->GetApiServerConfiguration();
if (get_config_result.has_error()) {
Json::Value error_json;
error_json["message"] = get_config_result.error();
auto resp = cortex_utils::CreateCortexHttpJsonResponse(error_json);
resp->setStatusCode(drogon::k400BadRequest);
callback(resp);
return;
}
auto resp = cortex_utils::CreateCortexHttpJsonResponse(
get_config_result.value().ToJson());
resp->setStatusCode(drogon::k200OK);
callback(resp);
(void)req;
return;
}
void Configs::UpdateConfigurations(
const HttpRequestPtr& req,
std::function<void(const HttpResponsePtr&)>&& callback) {
auto json_body = req->getJsonObject();
if (json_body == nullptr) {
Json::Value error_json;
error_json["message"] = "Configuration must be provided via JSON body";
auto resp = cortex_utils::CreateCortexHttpJsonResponse(error_json);
resp->setStatusCode(drogon::k400BadRequest);
callback(resp);
return;
}
auto update_config_result =
config_service_->UpdateApiServerConfiguration(*json_body);
if (update_config_result.has_error()) {
Json::Value error_json;
error_json["message"] = update_config_result.error();
auto resp = cortex_utils::CreateCortexHttpJsonResponse(error_json);
resp->setStatusCode(drogon::k400BadRequest);
callback(resp);
return;
}
Json::Value root;
root["message"] = "Configuration updated successfully";
root["config"] = update_config_result.value().ToJson();
auto resp = cortex_utils::CreateCortexHttpJsonResponse(root);
resp->setStatusCode(drogon::k200OK);
callback(resp);
return;
}