Initial commit
This commit is contained in:
commit
d17500a3b0
18 changed files with 938 additions and 0 deletions
controllers
43
controllers/api_v1_Devices.cc
Normal file
43
controllers/api_v1_Devices.cc
Normal file
|
@ -0,0 +1,43 @@
|
|||
#include "api_v1_Devices.h"
|
||||
using namespace api::v1;
|
||||
//add definition of your processing function here
|
||||
|
||||
void Devices::get_all(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback)
|
||||
{
|
||||
|
||||
std::cout << "Get All\n";
|
||||
|
||||
auto resp=HttpResponse::newHttpResponse();
|
||||
callback(resp);
|
||||
}
|
||||
|
||||
void Devices::get_one(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback,
|
||||
std::string device_id)
|
||||
{
|
||||
std::cout << "Get One: " << device_id << "\n";
|
||||
|
||||
auto resp=HttpResponse::newHttpResponse();
|
||||
callback(resp);
|
||||
}
|
||||
|
||||
void Devices::get_relays_all(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback,
|
||||
std::string device_id)
|
||||
{
|
||||
std::cout << "Get Relays All: " << device_id << "\n";
|
||||
|
||||
auto resp=HttpResponse::newHttpResponse();
|
||||
callback(resp);
|
||||
}
|
||||
|
||||
void Devices::get_relays_one(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback,
|
||||
std::string device_id, std::string relay_id)
|
||||
{
|
||||
std::cout << "Get Relays One: " << device_id << "; " << relay_id << "\n";
|
||||
|
||||
Json::Value ret;
|
||||
ret["result"] = "ok";
|
||||
ret["device_id"] = device_id;
|
||||
ret["relay_id"] = relay_id;
|
||||
auto resp = HttpResponse::newHttpJsonResponse(ret);
|
||||
callback(resp);
|
||||
}
|
24
controllers/api_v1_Devices.h
Normal file
24
controllers/api_v1_Devices.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
#pragma once
|
||||
#include <drogon/HttpController.h>
|
||||
using namespace drogon;
|
||||
namespace api
|
||||
{
|
||||
namespace v1
|
||||
{
|
||||
class Devices:public drogon::HttpController<Devices>
|
||||
{
|
||||
public:
|
||||
METHOD_LIST_BEGIN
|
||||
METHOD_ADD(Devices::get_all,"/",Get);
|
||||
METHOD_ADD(Devices::get_one,"/{1}",Get);
|
||||
METHOD_ADD(Devices::get_relays_all,"/{1}/relays",Get);
|
||||
METHOD_ADD(Devices::get_relays_one,"/{1}/relays/{2}",Get);
|
||||
METHOD_LIST_END
|
||||
|
||||
void get_all(const HttpRequestPtr& req,std::function<void (const HttpResponsePtr &)> &&callback);
|
||||
void get_one(const HttpRequestPtr& req,std::function<void (const HttpResponsePtr &)> &&callback,std::string device_id);
|
||||
void get_relays_all(const HttpRequestPtr& req,std::function<void (const HttpResponsePtr &)> &&callback,std::string device_id);
|
||||
void get_relays_one(const HttpRequestPtr& req,std::function<void (const HttpResponsePtr &)> &&callback,std::string device_id,std::string relay_id);
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue