updating changes

This commit is contained in:
krunal 2023-08-28 18:36:33 +05:30
parent 78576941cd
commit d582508404
5 changed files with 11 additions and 12 deletions

View File

@ -69,7 +69,7 @@ bool get_stopwords(const std::shared_ptr<http_req>& req, const std::shared_ptr<h
bool get_stopword(const std::shared_ptr<http_req>& req, const std::shared_ptr<http_res>& res);
bool upsert_stopword(const std::shared_ptr<http_req>& req, const std::shared_ptr<http_res>& res);
bool put_upsert_stopword(const std::shared_ptr<http_req>& req, const std::shared_ptr<http_res>& res);
bool del_stopword(const std::shared_ptr<http_req>& req, const std::shared_ptr<http_res>& res);

View File

@ -1932,7 +1932,7 @@ bool get_stopword(const std::shared_ptr<http_req>& req, const std::shared_ptr<ht
return true;
}
bool upsert_stopword(const std::shared_ptr<http_req>& req, const std::shared_ptr<http_res>& res) {
bool put_upsert_stopword(const std::shared_ptr<http_req>& req, const std::shared_ptr<http_res>& res) {
nlohmann::json req_json;
try {

View File

@ -70,7 +70,7 @@ void master_server_routes() {
server->get("/stopwords", get_stopwords);
server->get("/stopwords/:name", get_stopword);
server->put("/stopwords/:name", upsert_stopword);
server->put("/stopwords/:name", put_upsert_stopword);
server->del("/stopwords/:name", del_stopword);
// analytics

View File

@ -28,7 +28,7 @@ Option<bool> StopwordsManager::upsert_stopword(const std::string& stopword_name,
const char* STOPWORD_VALUES = "stopwords";
const char* STOPWORD_LOCALE = "locale";
bool locale_exist = false;
std::string locale = "";
if(stopwords_json.count(STOPWORD_VALUES) == 0){
return Option<bool>(400, (std::string("Parameter `") + STOPWORD_VALUES + "` is required"));
@ -39,10 +39,10 @@ Option<bool> StopwordsManager::upsert_stopword(const std::string& stopword_name,
}
if(stopwords_json.count(STOPWORD_LOCALE) != 0) {
locale_exist = true;
if (!stopwords_json[STOPWORD_LOCALE].is_string()) {
return Option<bool>(400, (std::string("Parameter `") + STOPWORD_LOCALE + "` is required as string value"));
}
locale = stopwords_json[STOPWORD_LOCALE];
}
if(write_to_store) {
@ -55,7 +55,6 @@ Option<bool> StopwordsManager::upsert_stopword(const std::string& stopword_name,
std::vector<std::string> tokens;
spp::sparse_hash_set<std::string> stopwords_set;
const auto& stopwords = stopwords_json[STOPWORD_VALUES];
const auto& locale = locale_exist? stopwords_json[STOPWORD_LOCALE] : "";
for (const auto &stopword: stopwords.items()) {
const auto& val = stopword.value().get<std::string>();

View File

@ -211,7 +211,7 @@ TEST_F(StopwordsManagerTest, StopwordsBasics) {
req->params["name"] = "articles";
req->body = stopword_value.dump();
auto result = upsert_stopword(req, res);
auto result = put_upsert_stopword(req, res);
if(!result) {
LOG(ERROR) << res->body;
FAIL();
@ -247,7 +247,7 @@ TEST_F(StopwordsManagerTest, StopwordsBasics) {
req->params["name"] = "continents";
req->body = stopword_value.dump();
result = upsert_stopword(req, res);
result = put_upsert_stopword(req, res);
if(!result) {
LOG(ERROR) << res->body;
FAIL();
@ -337,7 +337,7 @@ TEST_F(StopwordsManagerTest, StopwordsValidation) {
req->params["name"] = "continents";
req->body = stopword_value.dump();
auto result = upsert_stopword(req, res);
auto result = put_upsert_stopword(req, res);
ASSERT_EQ(400, res->status_code);
ASSERT_STREQ("{\"message\": \"Parameter `stopwords` is required\"}", res->body.c_str());
@ -350,7 +350,7 @@ TEST_F(StopwordsManagerTest, StopwordsValidation) {
req->params["name"] = "continents";
req->body = stopword_value.dump();
result = upsert_stopword(req, res);
result = put_upsert_stopword(req, res);
ASSERT_EQ(400, res->status_code);
ASSERT_STREQ("{\"message\": \"Parameter `locale` is required as string value\"}", res->body.c_str());
@ -362,7 +362,7 @@ TEST_F(StopwordsManagerTest, StopwordsValidation) {
req->params["name"] = "continents";
req->body = stopword_value.dump();
result = upsert_stopword(req, res);
result = put_upsert_stopword(req, res);
ASSERT_EQ(400, res->status_code);
ASSERT_STREQ("{\"message\": \"Parameter `stopwords` is required as string array value\"}", res->body.c_str());
@ -392,7 +392,7 @@ TEST_F(StopwordsManagerTest, ReloadStopwordsOnRestart) {
req->params["name"] = "genre";
req->body = stopword_value.dump();
auto result = upsert_stopword(req, res);
auto result = put_upsert_stopword(req, res);
if(!result) {
LOG(ERROR) << res->body;
FAIL();