MCPcopy Create free account
hub / github.com/Restream/reindexer / GetNamespaces

Method GetNamespaces

cpp_src/server/httpserver.cc:488–522  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

486}
487
488int HTTPServer::GetNamespaces(http::Context& ctx) {
489 const std::string_view sortOrder = ctx.request->params.Get("sort_order"sv);
490 ComparationResult comp = ComparationResult::NotComparable;
491 if (sortOrder == "asc"sv) {
492 comp = ComparationResult::Lt;
493 } else if (sortOrder == "desc"sv) {
494 comp = ComparationResult::Gt;
495 } else if (!sortOrder.empty()) {
496 return jsonStatus(ctx, http::HttpStatus(http::StatusBadRequest, "Invalid `sort_order` parameter"));
497 }
498
499 std::vector<reindexer::NamespaceDef> nsDefs;
500 const auto err = getDB<kRoleDataRead>(ctx).EnumNamespaces(nsDefs, EnumNamespacesOpts().OnlyNames());
501 if (!err.ok()) {
502 return jsonStatus(ctx, http::HttpStatus(err));
503 }
504
505 if (comp != ComparationResult::NotComparable) {
506 boost::sort::pdqsort(nsDefs.begin(), nsDefs.end(), [comp](const NamespaceDef& lhs, const NamespaceDef& rhs) {
507 return collateCompare<CollateASCII>(lhs.name, rhs.name, SortingPrioritiesTable()) == comp;
508 });
509 }
510
511 auto ser = makeRestrictedWrSerializer(ctx);
512 {
513 JsonBuilder builder(ser);
514 builder.Put("total_items", nsDefs.size());
515 auto arrNode = builder.Array("items");
516 for (auto& nsDef : nsDefs) {
517 auto objNode = arrNode.Object();
518 objNode.Put("name", nsDef.name);
519 }
520 }
521 return ctx.JSON(http::StatusOK, ser.DetachChunk());
522}
523
524int HTTPServer::GetNamespace(http::Context& ctx) {
525 const std::string nsName = urldecode2(ctx.request->urlParams[1]);

Callers 6

TEST_FFunction · 0.45
queryResultsJSONMethod · 0.45
queryResultsProtobufMethod · 0.45
queryResultParamsMethod · 0.45
CommitTxMethod · 0.45

Calls 15

HttpStatusClass · 0.85
okMethod · 0.80
EnumNamespacesOptsClass · 0.50
GetMethod · 0.45
emptyMethod · 0.45
EnumNamespacesMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
PutMethod · 0.45
sizeMethod · 0.45
ArrayMethod · 0.45

Tested by 2

TEST_FFunction · 0.36