create TESTING
This commit is contained in:
@@ -38,12 +38,18 @@ bool ApiServer::enqueueRequest(const nlohmann::json& request, httplib::Response&
|
||||
|
||||
nlohmann::json ApiServer::toMirQueueEntry(const nlohmann::json& entry) const
|
||||
{
|
||||
return nlohmann::json{{"id", entry.value("id", 0)},
|
||||
{"mission_id", entry.value("mission_id", "")},
|
||||
{"state", entry.value("status", "pending")},
|
||||
{"message", entry.value("mission_name", "")},
|
||||
{"priority", entry.value("priority", 0)},
|
||||
{"robot_id", entry.value("robot_id", "default")}};
|
||||
nlohmann::json out = nlohmann::json::object();
|
||||
if (entry.contains("id"))
|
||||
out["id"] = entry["id"];
|
||||
out["mission_id"] = entry.value("mission_id", std::string(""));
|
||||
out["state"] = entry.contains("status") ? entry["status"] : nlohmann::json("pending");
|
||||
out["message"] = entry.value("mission_name", std::string(""));
|
||||
if (entry.contains("priority") && entry["priority"].is_number())
|
||||
out["priority"] = entry["priority"];
|
||||
else
|
||||
out["priority"] = 0;
|
||||
out["robot_id"] = entry.value("robot_id", std::string("default"));
|
||||
return out;
|
||||
}
|
||||
|
||||
void ApiServer::registerMissionRoutes(httplib::Server& svr)
|
||||
@@ -226,10 +232,14 @@ void ApiServer::registerMirV2Routes(httplib::Server& svr)
|
||||
svr.Get("/api/v2.0.0/mission_queue", [this](const httplib::Request&, httplib::Response& res) {
|
||||
HttpUtil::addCors(res);
|
||||
nlohmann::json out = nlohmann::json::array();
|
||||
for (const auto& item : mission_queue_.list())
|
||||
const nlohmann::json queue = mission_queue_.list();
|
||||
if (queue.is_array())
|
||||
{
|
||||
if (item.is_object())
|
||||
out.push_back(toMirQueueEntry(item));
|
||||
for (const auto& item : queue)
|
||||
{
|
||||
if (item.is_object())
|
||||
out.push_back(toMirQueueEntry(item));
|
||||
}
|
||||
}
|
||||
res.set_header("Content-Type", "application/json; charset=utf-8");
|
||||
res.body = out.dump();
|
||||
@@ -248,10 +258,17 @@ void ApiServer::registerMirV2Routes(httplib::Server& svr)
|
||||
}
|
||||
if (!payload.contains("source"))
|
||||
payload["source"] = "rest_api_v2";
|
||||
if (!enqueueRequest(payload, res, 201))
|
||||
return;
|
||||
nlohmann::json created = nlohmann::json::parse(res.body);
|
||||
res.body = toMirQueueEntry(created).dump();
|
||||
nlohmann::json built;
|
||||
std::string err;
|
||||
if (!MissionEnqueue::buildPayload(mission_store_, payload, built, err))
|
||||
return HttpUtil::jsonError(res, 400, err);
|
||||
const auto entry = mission_queue_.enqueue(built, err);
|
||||
if (!entry)
|
||||
return HttpUtil::jsonError(res, 400, err);
|
||||
HttpUtil::addCors(res);
|
||||
res.status = 201;
|
||||
res.set_header("Content-Type", "application/json; charset=utf-8");
|
||||
res.body = toMirQueueEntry(*entry).dump();
|
||||
});
|
||||
|
||||
svr.Delete("/api/v2.0.0/mission_queue", [this](const httplib::Request&, httplib::Response& res) {
|
||||
|
||||
Reference in New Issue
Block a user