add: CORS and OPTIONS

add: 'off' schedule in db init
add: copy db to build dir
This commit is contained in:
Tobias Reisinger 2019-09-08 23:24:31 +02:00
parent e93ea44350
commit 8679bfe680
7 changed files with 32 additions and 59 deletions

View file

@ -1,23 +1,21 @@
#pragma once
#include <drogon/HttpController.h>
using namespace drogon;
namespace api
{
namespace v1
namespace api::v1
{
class controllers:public drogon::HttpController<controllers>
{
public:
METHOD_LIST_BEGIN
METHOD_ADD(controllers::post_discover, "/discover", Post);
METHOD_ADD(controllers::get_all, "/", Get);
METHOD_ADD(controllers::get_one_by_id, "/{1}", Get);
METHOD_ADD(controllers::delete_one_by_id, "/{1}", Delete);
METHOD_ADD(controllers::put_one_by_id, "/{1}", Put, "filters::json_required", "filters::controllers::valid_json");
METHOD_ADD(controllers::post_discover, "/discover", Post, Options);
METHOD_ADD(controllers::get_all, "/", Get, Options);
METHOD_ADD(controllers::get_one_by_id, "/{1}", Get, Options);
METHOD_ADD(controllers::delete_one_by_id, "/{1}", Delete, Options);
METHOD_ADD(controllers::put_one_by_id, "/{1}", Put, Options, "filters::json_required", "filters::controllers::valid_json");
METHOD_ADD(controllers::get_relays_all, "/{1}/relays/", Get);
METHOD_ADD(controllers::get_relays_one_by_id_and_num, "/{1}/relays/{2}", Get);
METHOD_ADD(controllers::put_relays_one_by_id_and_num, "/{1}/relays/{2}", Put, "filters::json_required", "filters::relays::valid_json");
METHOD_ADD(controllers::get_relays_all, "/{1}/relays/", Get, Options);
METHOD_ADD(controllers::get_relays_one_by_id_and_num, "/{1}/relays/{2}", Get, Options);
METHOD_ADD(controllers::put_relays_one_by_id_and_num, "/{1}/relays/{2}", Put, Options, "filters::json_required", "filters::relays::valid_json");
METHOD_LIST_END
static void post_discover(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback);
@ -31,4 +29,3 @@ namespace api
static void put_relays_one_by_id_and_num(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback, const std::string& controller_id, int relay_num);
};
}
}

View file

@ -1,18 +1,15 @@
#pragma once
#include <drogon/HttpController.h>
using namespace drogon;
namespace api
{
namespace v1
namespace api::v1
{
class relays:public drogon::HttpController<relays>
{
public:
METHOD_LIST_BEGIN
METHOD_ADD(relays::get_all, "/", Get);
METHOD_ADD(relays::get_all, "/", Get, Options);
METHOD_LIST_END
static void get_all(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback);
};
}
}

View file

@ -1,19 +1,17 @@
#pragma once
#include <drogon/HttpController.h>
using namespace drogon;
namespace api
{
namespace v1
namespace api::v1
{
class schedules:public drogon::HttpController<schedules>
{
public:
METHOD_LIST_BEGIN
METHOD_ADD(schedules::post_new, "/", Post, "filters::json_required", "filters::schedules::valid_json");
METHOD_ADD(schedules::get_all, "/", Get);
METHOD_ADD(schedules::get_one_by_id, "/{1}", Get);
METHOD_ADD(schedules::delete_one_by_id, "/{1}", Delete);
METHOD_ADD(schedules::put_one_by_id, "/{1}", Put, "filters::json_required", "filters::schedules::valid_json");
METHOD_ADD(schedules::post_new, "/", Post, Options, "filters::json_required", "filters::schedules::valid_json");
METHOD_ADD(schedules::get_all, "/", Get, Options);
METHOD_ADD(schedules::get_one_by_id, "/{1}", Get, Options);
METHOD_ADD(schedules::delete_one_by_id, "/{1}", Delete, Options);
METHOD_ADD(schedules::put_one_by_id, "/{1}", Put, Options, "filters::json_required", "filters::schedules::valid_json");
//METHOD_ADD(controllers::get_relays_all,"/{1}/relays",Get);
//METHOD_ADD(controllers::get_relays_one,"/{1}/relays/{2}",Get);
METHOD_LIST_END
@ -27,4 +25,3 @@ namespace api
//void get_relays_one(const HttpRequestPtr& req,std::function<void (const HttpResponsePtr &)> &&callback,std::string schedule_id,std::string relay_id);
};
}
}