From a3fa6aa98723d5022212dfb8e5ed285102bd2807 Mon Sep 17 00:00:00 2001 From: Ken Zangelin Date: Fri, 14 Aug 2015 00:36:12 +0200 Subject: [PATCH] Implemented 'options=count' --- src/lib/serviceRoutinesV2/getEntityAllTypes.cpp | 17 ++++++++++++++++- .../get_all_entity_types.test | 3 ++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/lib/serviceRoutinesV2/getEntityAllTypes.cpp b/src/lib/serviceRoutinesV2/getEntityAllTypes.cpp index ad5a7a6bc1..1921ac7157 100644 --- a/src/lib/serviceRoutinesV2/getEntityAllTypes.cpp +++ b/src/lib/serviceRoutinesV2/getEntityAllTypes.cpp @@ -55,7 +55,22 @@ std::string getEntityAllTypes mongoEntityTypes(&response, ciP->tenant, ciP->servicePathV, ciP->uriParam); answer = response.toJson(ciP); - response.release(); + if (ciP->uriParam["options"] == "count") + { + long long acc = 0; + char cVec[64]; + + for (unsigned int ix = 0; ix < response.typeEntityVector.size(); ++ix) + { + acc += response.typeEntityVector[ix]->count; + } + + snprintf(cVec, sizeof(cVec), "%lld", acc); + ciP->httpHeader.push_back("X-Total-Count"); + ciP->httpHeaderValue.push_back(cVec); + } + + response.release(); return answer; } diff --git a/test/functionalTest/cases/1027_get_all_entity_types/get_all_entity_types.test b/test/functionalTest/cases/1027_get_all_entity_types/get_all_entity_types.test index 67e9c68a9a..cdc22aac88 100644 --- a/test/functionalTest/cases/1027_get_all_entity_types/get_all_entity_types.test +++ b/test/functionalTest/cases/1027_get_all_entity_types/get_all_entity_types.test @@ -116,7 +116,7 @@ echo echo "08. GET /v2/type and get a list of three types, T3 now has three attributes and two entities" echo "============================================================================================" -orionCurl --url /v2/type --json +orionCurl --url /v2/type?options=count --json echo echo @@ -239,6 +239,7 @@ Date: REGEX(.*) HTTP/1.1 200 OK Content-Length: 233 Content-Type: application/json +X-Total-Count: 4 Date: REGEX(.*) {