From 6cdbb29d4a5e26d08a4069aee5dc2b42d29cb8a6 Mon Sep 17 00:00:00 2001 From: Kishore Nallan Date: Thu, 29 Mar 2018 08:08:22 +0530 Subject: [PATCH] Fix `num_documents` & `facet` fields not returned when creating a new collection. --- include/option.h | 2 +- src/api.cpp | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/include/option.h b/include/option.h index e1fb135e..94b2d899 100644 --- a/include/option.h +++ b/include/option.h @@ -32,7 +32,7 @@ public: return is_ok; } - T get() { + T get() const { return value; } diff --git a/src/api.cpp b/src/api.cpp index eddf1689..7835276d 100644 --- a/src/api.cpp +++ b/src/api.cpp @@ -120,8 +120,15 @@ void post_create_collection(http_req & req, http_res & res) { } const std::string & default_sorting_field = req_json[DEFAULT_SORTING_FIELD].get(); - collectionManager.create_collection(req_json["name"], fields, default_sorting_field); - res.send_201(req.body); + const Option & collection_op = + collectionManager.create_collection(req_json["name"], fields, default_sorting_field); + + if(collection_op.ok()) { + nlohmann::json json_response = collection_summary_json(collection_op.get()); + return res.send_201(json_response.dump()); + } + + return res.send(collection_op.code(), collection_op.error()); } void del_drop_collection(http_req & req, http_res & res) {