2019-07-22 20:26:42 +00:00
|
|
|
#include <netdb.h>
|
|
|
|
#include <models/relay_dbo.h>
|
|
|
|
#include <helpers.h>
|
|
|
|
#include "api_v1_relays.h"
|
|
|
|
using namespace api::v1;
|
|
|
|
|
|
|
|
void
|
|
|
|
relays::get_all(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback)
|
|
|
|
{
|
|
|
|
relay_dbo **all_relays = relay_dbo::get_all();
|
|
|
|
Json::Value all_relays_json(Json::arrayValue);
|
|
|
|
|
|
|
|
for(int i = 0; all_relays[i] != nullptr; i++)
|
|
|
|
{
|
|
|
|
all_relays_json.append(all_relays[i]->to_json());
|
|
|
|
}
|
|
|
|
|
|
|
|
auto resp = HttpResponse::newHttpJsonResponse(all_relays_json);
|
|
|
|
|
|
|
|
callback(resp);
|
|
|
|
|
|
|
|
relay_dbo::free_list(all_relays);
|
|
|
|
}
|
2019-09-24 21:33:35 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
relays::get_one_by_tag(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback,
|
|
|
|
const std::string &relay_tag)
|
|
|
|
{
|
2020-02-23 19:06:14 +00:00
|
|
|
relay_dbo **relays = relay_dbo::get_by_simple("tag", relay_tag.c_str(), (intptr_t)&sqlite3_bind_text, -1);
|
2019-09-24 21:33:35 +00:00
|
|
|
|
|
|
|
if(relays[0])
|
|
|
|
{
|
|
|
|
auto resp = HttpResponse::newHttpJsonResponse(relays[0]->to_json());
|
|
|
|
|
|
|
|
callback(resp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto resp = HttpResponse::newHttpResponse();
|
|
|
|
resp->setStatusCode(k404NotFound);
|
|
|
|
|
|
|
|
callback(resp);
|
|
|
|
}
|
|
|
|
relay_dbo::free_list(relays);
|
2020-02-23 19:06:14 +00:00
|
|
|
}
|