From 1554bead10cf1ea12a95b2b8ea23e22520e6a1ab Mon Sep 17 00:00:00 2001 From: travisladuke Date: Wed, 31 Jan 2024 09:41:29 -0800 Subject: [PATCH] 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{} --- controller/EmbeddedNetworkController.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/controller/EmbeddedNetworkController.cpp b/controller/EmbeddedNetworkController.cpp index 57eecb4a2..a5373423c 100644 --- a/controller/EmbeddedNetworkController.cpp +++ b/controller/EmbeddedNetworkController.cpp @@ -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 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);