add: relays get all api endpoint
This commit is contained in:
parent
368df26ad7
commit
8d4ad2f631
2 changed files with 43 additions and 0 deletions
25
controllers/api_v1_relays.cc
Normal file
25
controllers/api_v1_relays.cc
Normal file
|
@ -0,0 +1,25 @@
|
|||
#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());
|
||||
}
|
||||
|
||||
Json::StreamWriterBuilder jw;
|
||||
|
||||
auto resp = HttpResponse::newHttpJsonResponse(all_relays_json);
|
||||
|
||||
callback(resp);
|
||||
|
||||
relay_dbo::free_list(all_relays);
|
||||
}
|
18
controllers/api_v1_relays.h
Normal file
18
controllers/api_v1_relays.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
#pragma once
|
||||
#include <drogon/HttpController.h>
|
||||
using namespace drogon;
|
||||
namespace api
|
||||
{
|
||||
namespace v1
|
||||
{
|
||||
class relays:public drogon::HttpController<relays>
|
||||
{
|
||||
public:
|
||||
METHOD_LIST_BEGIN
|
||||
METHOD_ADD(relays::get_all, "/", Get);
|
||||
METHOD_LIST_END
|
||||
|
||||
static void get_all(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback);
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue