diff --git a/core/src/server/web_impl/handler/WebRequestHandler.cpp b/core/src/server/web_impl/handler/WebRequestHandler.cpp index 7e633f8b9be267913eda4db9055794bbafbb975e..c5b8c59f06f57b849ed5708ba800e215fcfabe20 100644 --- a/core/src/server/web_impl/handler/WebRequestHandler.cpp +++ b/core/src/server/web_impl/handler/WebRequestHandler.cpp @@ -78,58 +78,6 @@ WebErrorMap(ErrorCode code) { } /////////////////////////////////// Private methods /////////////////////////////////////// -Status -WebRequestHandler::ParseQueryInteger(const OQueryParams& query_params, const std::string& key, int64_t& value, - bool nullable) { - auto query = query_params.get(key.c_str()); - if (nullptr != query.get() && query->getSize() > 0) { - std::string value_str = query->std_str(); - if (!ValidationUtil::ValidateStringIsNumber(value_str).ok()) { - return Status(ILLEGAL_QUERY_PARAM, - "Query param \'offset\' is illegal, only non-negative integer supported"); - } - - value = std::stol(value_str); - } else if (!nullable) { - return Status(QUERY_PARAM_LOSS, "Query param \"" + key + "\" is required"); - } - - return Status::OK(); -} - -Status -WebRequestHandler::ParseQueryStr(const OQueryParams& query_params, const std::string& key, std::string& value, - bool nullable) { - auto query = query_params.get(key.c_str()); - if (nullptr != query.get() && query->getSize() > 0) { - value = query->std_str(); - } else if (!nullable) { - return Status(QUERY_PARAM_LOSS, "Query param \"" + key + "\" is required"); - } - - return Status::OK(); -} - -Status -WebRequestHandler::ParseQueryBool(const OQueryParams& query_params, const std::string& key, bool& value, - bool nullable) { - auto query = query_params.get(key.c_str()); - if (nullptr != query.get() && query->getSize() > 0) { - std::string value_str = query->std_str(); - if (!ValidationUtil::ValidateStringIsBool(value_str).ok()) { - return Status(ILLEGAL_QUERY_PARAM, "Query param \'all_required\' must be a bool"); - } - value = value_str == "True" || value_str == "true"; - return Status::OK(); - } - - if (!nullable) { - return Status(QUERY_PARAM_LOSS, "Query param \"" + key + "\" is required"); - } - - return Status::OK(); -} - void WebRequestHandler::AddStatusToJson(nlohmann::json& json, int64_t code, const std::string& msg) { json["code"] = (int64_t)code; diff --git a/core/src/server/web_impl/handler/WebRequestHandler.h b/core/src/server/web_impl/handler/WebRequestHandler.h index 6c1c689a309428f65c70d845925c0b54b2af94ea..df6b234e6d5acc5858bcdaf7e09ba981f1605b1d 100644 --- a/core/src/server/web_impl/handler/WebRequestHandler.h +++ b/core/src/server/web_impl/handler/WebRequestHandler.h @@ -77,16 +77,6 @@ class WebRequestHandler { return context_ptr; } - private: - Status - ParseQueryInteger(const OQueryParams& query_params, const std::string& key, int64_t& value, bool nullable = true); - - Status - ParseQueryStr(const OQueryParams& query_params, const std::string& key, std::string& value, bool nullable = true); - - Status - ParseQueryBool(const OQueryParams& query_params, const std::string& key, bool& value, bool nullable = true); - private: void AddStatusToJson(nlohmann::json& json, int64_t code, const std::string& msg); diff --git a/core/src/server/web_impl/utils/Util.cpp b/core/src/server/web_impl/utils/Util.cpp index 0108e8ab99b22d4ad4be801d50673a12a1f9b24b..aa1a1820b33999f7de780cbffac855ed83fa7fac 100644 --- a/core/src/server/web_impl/utils/Util.cpp +++ b/core/src/server/web_impl/utils/Util.cpp @@ -11,6 +11,8 @@ #include "server/web_impl/utils/Util.h" +#include "utils/ValidationUtil.h" + namespace milvus { namespace server { namespace web { @@ -54,6 +56,55 @@ CopyBinRowRecords(const OList::ObjectWrapper>::ObjectWrapper& reco return Status::OK(); } +Status +ParseQueryInteger(const OQueryParams& query_params, const std::string& key, int64_t& value, bool nullable) { + auto query = query_params.get(key.c_str()); + if (nullptr != query.get() && query->getSize() > 0) { + std::string value_str = query->std_str(); + if (!ValidationUtil::ValidateStringIsNumber(value_str).ok()) { + return Status(ILLEGAL_QUERY_PARAM, + "Query param \'offset\' is illegal, only non-negative integer supported"); + } + + value = std::stol(value_str); + } else if (!nullable) { + return Status(QUERY_PARAM_LOSS, "Query param \"" + key + "\" is required"); + } + + return Status::OK(); +} + +Status +ParseQueryStr(const OQueryParams& query_params, const std::string& key, std::string& value, bool nullable) { + auto query = query_params.get(key.c_str()); + if (nullptr != query.get() && query->getSize() > 0) { + value = query->std_str(); + } else if (!nullable) { + return Status(QUERY_PARAM_LOSS, "Query param \"" + key + "\" is required"); + } + + return Status::OK(); +} + +Status +ParseQueryBool(const OQueryParams& query_params, const std::string& key, bool& value, bool nullable) { + auto query = query_params.get(key.c_str()); + if (nullptr != query.get() && query->getSize() > 0) { + std::string value_str = query->std_str(); + if (!ValidationUtil::ValidateStringIsBool(value_str).ok()) { + return Status(ILLEGAL_QUERY_PARAM, "Query param \'all_required\' must be a bool"); + } + value = value_str == "True" || value_str == "true"; + return Status::OK(); + } + + if (!nullable) { + return Status(QUERY_PARAM_LOSS, "Query param \"" + key + "\" is required"); + } + + return Status::OK(); +} + } // namespace web } // namespace server } // namespace milvus diff --git a/core/src/server/web_impl/utils/Util.h b/core/src/server/web_impl/utils/Util.h index fe3721e6e8bc7f4ebff72e788f0e2edbaa58e762..9ceaa37ace406eb0cac198465053169750118982 100644 --- a/core/src/server/web_impl/utils/Util.h +++ b/core/src/server/web_impl/utils/Util.h @@ -28,6 +28,15 @@ CopyRowRecords(const OList::ObjectWrapper>::ObjectWrapper& recor Status CopyBinRowRecords(const OList::ObjectWrapper>::ObjectWrapper& records, std::vector& vectors); +Status +ParseQueryInteger(const OQueryParams& query_params, const std::string& key, int64_t& value, bool nullable = true); + +Status +ParseQueryStr(const OQueryParams& query_params, const std::string& key, std::string& value, bool nullable = true); + +Status +ParseQueryBool(const OQueryParams& query_params, const std::string& key, bool& value, bool nullable = true); + } // namespace web } // namespace server } // namespace milvus