Skip to content

Commit

Permalink
Fixed #8: check if collection pointer is null when collection does no…
Browse files Browse the repository at this point in the history
…t exist.
  • Loading branch information
kishorenc committed Jan 4, 2018
1 parent 9407f55 commit 70a6147
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,14 @@ void post_create_collection(http_req & req, http_res & res) {

void del_drop_collection(http_req & req, http_res & res) {
std::string doc_id = req.params["id"];

CollectionManager & collectionManager = CollectionManager::get_instance();
Collection* collection = collectionManager.get_collection(req.params["collection"]);
nlohmann::json collection_json = collection_summary_json(collection);

if(!collection) {
return res.send_404();
}

nlohmann::json collection_json = collection_summary_json(collection);
Option<bool> drop_result = collectionManager.drop_collection(req.params["collection"]);

if(!drop_result.ok()) {
Expand All @@ -146,7 +149,8 @@ void get_search(http_req & req, http_res & res) {
const char *NUM_TYPOS = "num_typos";
const char *PREFIX = "prefix";
const char *FILTER = "filter_by";
const char *SEARCH_BY = "query_by";
const char *QUERY = "q";
const char *QUERY_BY = "query_by";
const char *SORT_BY = "sort_by";
const char *FACET_BY = "facet_by";
const char *PER_PAGE = "per_page";
Expand All @@ -162,8 +166,12 @@ void get_search(http_req & req, http_res & res) {
req.params[PREFIX] = "false";
}

if(req.params.count(SEARCH_BY) == 0) {
return res.send_400(std::string("Parameter `") + SEARCH_BY + "` is required.");
if(req.params.count(QUERY) == 0) {
return res.send_400(std::string("Parameter `") + QUERY + "` is required.");
}

if(req.params.count(QUERY_BY) == 0) {
return res.send_400(std::string("Parameter `") + QUERY_BY + "` is required.");
}

if(req.params.count(PER_PAGE) == 0) {
Expand All @@ -189,7 +197,7 @@ void get_search(http_req & req, http_res & res) {
std::string filter_str = req.params.count(FILTER) != 0 ? req.params[FILTER] : "";

std::vector<std::string> search_fields;
StringUtils::split(req.params[SEARCH_BY], search_fields, ",");
StringUtils::split(req.params[QUERY_BY], search_fields, ",");

std::vector<std::string> facet_fields;
StringUtils::split(req.params[FACET_BY], facet_fields, ",");
Expand Down Expand Up @@ -236,7 +244,7 @@ void get_search(http_req & req, http_res & res) {
StringUtils::toupper(req.params[RANK_TOKENS_BY]);
token_ordering token_order = (req.params[RANK_TOKENS_BY] == "TOKEN_RANKING_FIELD") ? MAX_SCORE : FREQUENCY;

Option<nlohmann::json> result_op = collection->search(req.params["q"], search_fields, filter_str, facet_fields,
Option<nlohmann::json> result_op = collection->search(req.params[QUERY], search_fields, filter_str, facet_fields,
sort_fields, std::stoi(req.params[NUM_TYPOS]),
std::stoi(req.params[PER_PAGE]), std::stoi(req.params[PAGE]),
token_order, prefix);
Expand Down Expand Up @@ -284,6 +292,11 @@ void get_collection_summary(http_req & req, http_res & res) {
void collection_export_handler(http_req* req, http_res* res, void* data) {
CollectionManager & collectionManager = CollectionManager::get_instance();
Collection* collection = collectionManager.get_collection(req->params["collection"]);

if(!collection) {
return res->send_404();
}

const std::string seq_id_prefix = collection->get_seq_id_collection_prefix();

rocksdb::Iterator* it = reinterpret_cast<rocksdb::Iterator*>(data);
Expand Down

0 comments on commit 70a6147

Please sign in to comment.