Implemented 'skip_waypoints' for the 'Nearest' service.

It actually makes no sence, as the only output on the 'Nearest' service
is a list of wypoints. On the other hand it can be used now as a simple
health check.
This commit is contained in:
Denis Chaplygin 2019-09-16 11:44:08 +03:00
parent 10c1b38139
commit 1b47242a58

View File

@ -6,6 +6,7 @@
#include "engine/api/json_factory.hpp" #include "engine/api/json_factory.hpp"
#include "engine/phantom_node.hpp" #include "engine/phantom_node.hpp"
#include "base_result.hpp"
#include <boost/assert.hpp> #include <boost/assert.hpp>
@ -54,6 +55,8 @@ class NearestAPI final : public BaseAPI
data_version_string = fb_result.CreateString(data_timestamp); data_version_string = fb_result.CreateString(data_timestamp);
} }
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbresult::Waypoint>>> waypoints_vector;
if (!parameters.skip_waypoints) {
std::vector<flatbuffers::Offset<fbresult::Waypoint>> waypoints; std::vector<flatbuffers::Offset<fbresult::Waypoint>> waypoints;
waypoints.resize(phantom_nodes.front().size()); waypoints.resize(phantom_nodes.front().size());
std::transform(phantom_nodes.front().begin(), std::transform(phantom_nodes.front().begin(),
@ -71,8 +74,11 @@ class NearestAPI final : public BaseAPI
return waypoint.Finish(); return waypoint.Finish();
}); });
auto waypoints_vector = fb_result.CreateVector(waypoints); waypoints_vector = fb_result.CreateVector(waypoints);
}
fbresult::FBResultBuilder response(fb_result); fbresult::FBResultBuilder response(fb_result);
response.add_waypoints(waypoints_vector); response.add_waypoints(waypoints_vector);
if (data_version_string) if (data_version_string)
{ {
@ -83,6 +89,7 @@ class NearestAPI final : public BaseAPI
void MakeResponse(const std::vector<std::vector<PhantomNodeWithDistance>> &phantom_nodes, void MakeResponse(const std::vector<std::vector<PhantomNodeWithDistance>> &phantom_nodes,
util::json::Object &response) const util::json::Object &response) const
{ {
if (!parameters.skip_waypoints) {
util::json::Array waypoints; util::json::Array waypoints;
waypoints.values.resize(phantom_nodes.front().size()); waypoints.values.resize(phantom_nodes.front().size());
std::transform(phantom_nodes.front().begin(), std::transform(phantom_nodes.front().begin(),
@ -102,9 +109,10 @@ class NearestAPI final : public BaseAPI
return waypoint; return waypoint;
}); });
response.values["waypoints"] = std::move(waypoints);
}
response.values["code"] = "Ok"; response.values["code"] = "Ok";
response.values["waypoints"] = std::move(waypoints);
} }
const NearestParameters &parameters; const NearestParameters &parameters;