Skip to content

Commit

Permalink
Improve members2 endpoint
Browse files Browse the repository at this point in the history
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{}
  • Loading branch information
laduke committed Feb 1, 2024
1 parent ff48cfa commit 685add6
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions controller/EmbeddedNetworkController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ void EmbeddedNetworkController::configureHTTPControlPlane(
std::string networkPath = "/controller/network/([0-9a-fA-F]{16})";
std::string oldAndBustedNetworkCreatePath = "/controller/network/([0-9a-fA-F]{10})______";
std::string memberListPath = "/controller/network/([0-9a-fA-F]{16})/member";
std::string memberListPath2 = "/controller/network/([0-9a-fA-F]{16})/member2";
std::string memberListPath2 = "/unstable/controller/network/([0-9a-fA-F]{16})/member";
std::string memberPath = "/controller/network/([0-9a-fA-F]{16})/member/([0-9a-fA-F]{10})";

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

auto out = nlohmann::json::array();
auto out = nlohmann::json::object();
auto meta = nlohmann::json::object();
auto members = nlohmann::json::array();
std::vector<json> memTmp;
if (_db.get(nwid, network, memTmp)) {
out.push_back(memTmp);
members.push_back(memTmp);
}

uint64_t authorizedCount = 0;
uint64_t totalCount = memTmp.size();
for (auto m = memTmp.begin(); m != memTmp.end(); ++m) {
bool a = OSUtils::jsonBool((*m)["authorized"], 0);
if (a) { authorizedCount++; }
}

meta["totalCount"] = totalCount;
meta["authorizedCount"] = authorizedCount;

out["data"] = members;
out["meta"] = meta;

setContent(req, res, out.dump());
};
s.Get(memberListPath2, memberListGet2);
Expand Down

0 comments on commit 685add6

Please sign in to comment.