Skip to content

Commit 685add6

Browse files
committed
Improve members2 endpoint
Move members list data inside data[] Putting the actual data inside data[] lets you extend the response without breaking changes. Added totalCount and authorized count to meta{}
1 parent ff48cfa commit 685add6

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

controller/EmbeddedNetworkController.cpp

+18-3
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ void EmbeddedNetworkController::configureHTTPControlPlane(
872872
std::string networkPath = "/controller/network/([0-9a-fA-F]{16})";
873873
std::string oldAndBustedNetworkCreatePath = "/controller/network/([0-9a-fA-F]{10})______";
874874
std::string memberListPath = "/controller/network/([0-9a-fA-F]{16})/member";
875-
std::string memberListPath2 = "/controller/network/([0-9a-fA-F]{16})/member2";
875+
std::string memberListPath2 = "/unstable/controller/network/([0-9a-fA-F]{16})/member";
876876
std::string memberPath = "/controller/network/([0-9a-fA-F]{16})/member/([0-9a-fA-F]{10})";
877877

878878
auto controllerGet = [&, setContent](const httplib::Request &req, httplib::Response &res) {
@@ -1045,12 +1045,27 @@ void EmbeddedNetworkController::configureHTTPControlPlane(
10451045
return;
10461046
}
10471047

1048-
auto out = nlohmann::json::array();
1048+
auto out = nlohmann::json::object();
1049+
auto meta = nlohmann::json::object();
1050+
auto members = nlohmann::json::array();
10491051
std::vector<json> memTmp;
10501052
if (_db.get(nwid, network, memTmp)) {
1051-
out.push_back(memTmp);
1053+
members.push_back(memTmp);
10521054
}
10531055

1056+
uint64_t authorizedCount = 0;
1057+
uint64_t totalCount = memTmp.size();
1058+
for (auto m = memTmp.begin(); m != memTmp.end(); ++m) {
1059+
bool a = OSUtils::jsonBool((*m)["authorized"], 0);
1060+
if (a) { authorizedCount++; }
1061+
}
1062+
1063+
meta["totalCount"] = totalCount;
1064+
meta["authorizedCount"] = authorizedCount;
1065+
1066+
out["data"] = members;
1067+
out["meta"] = meta;
1068+
10541069
setContent(req, res, out.dump());
10551070
};
10561071
s.Get(memberListPath2, memberListGet2);

0 commit comments

Comments
 (0)