fix: save id as blob, not as string
add: some progress to new discovery add: some tests remove: migrations. restarting for now
This commit is contained in:
parent
b4eec336a2
commit
51ab1d7982
22 changed files with 345 additions and 121 deletions
|
@ -63,14 +63,22 @@ configure_file("config.json" "config.json" COPYONLY)
|
|||
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
add_executable(core ${SRC_DIR} ${CTL_SRC} ${FILTER_SRC} ${VIEWSRC} ${PLUGIN_SRC} ${MODEL_SRC} ${HELPER_SRC})
|
||||
|
||||
add_custom_target(compiled_migrations ${CMAKE_CURRENT_SOURCE_DIR}/compile_migrations.sh)
|
||||
add_dependencies(core compiled_migrations)
|
||||
|
||||
add_subdirectory(drogon)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE drogon)
|
||||
|
||||
add_custom_target(migrations
|
||||
COMMAND ./compile_migrations.sh
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
add_custom_target(run
|
||||
COMMAND core
|
||||
DEPENDS core
|
||||
WORKING_DIRECTORY ${CMAKE_PROJECT_DIR}
|
||||
)
|
||||
|
||||
add_custom_target(test
|
||||
COMMAND tavern-ci --tavern-beta-new-traceback ./tavern_tests
|
||||
DEPENDS core
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
)
|
||||
|
|
|
@ -23,9 +23,17 @@ controllers::get_all(const HttpRequestPtr &req, std::function<void(const HttpRes
|
|||
|
||||
void
|
||||
controllers::get_one_by_id(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback,
|
||||
const std::string& controller_id)
|
||||
const std::string& controller_id_str)
|
||||
{
|
||||
controller_dbo **controllers = controller_dbo::get_by_simple("id", controller_id.c_str(), (intptr_t) &sqlite3_bind_text);
|
||||
uuid_t controller_id;
|
||||
if(uuid_parse(controller_id_str.c_str(), controller_id))
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k400BadRequest);
|
||||
callback(resp);
|
||||
return;
|
||||
}
|
||||
controller_dbo **controllers = controller_dbo::get_by_simple("id", controller_id, (intptr_t) &sqlite3_bind_blob, sizeof(uuid_t));
|
||||
|
||||
if(controllers[0])
|
||||
{
|
||||
|
@ -47,7 +55,7 @@ void
|
|||
controllers::get_one_by_tag(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback,
|
||||
const std::string &controller_tag)
|
||||
{
|
||||
controller_dbo **controllers = controller_dbo::get_by_simple("tag", controller_tag.c_str(), (intptr_t) &sqlite3_bind_text);
|
||||
controller_dbo **controllers = controller_dbo::get_by_simple("tag", controller_tag.c_str(), (intptr_t) &sqlite3_bind_text, -1);
|
||||
|
||||
if(controllers[0])
|
||||
{
|
||||
|
@ -66,9 +74,17 @@ controllers::get_one_by_tag(const HttpRequestPtr &req, std::function<void(const
|
|||
}
|
||||
|
||||
void
|
||||
controllers::delete_one_by_id(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback, const std::string& controller_id)
|
||||
controllers::delete_one_by_id(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback, const std::string& controller_id_str)
|
||||
{
|
||||
controller_dbo **controllers = controller_dbo::get_by_simple("id", controller_id.c_str(), (intptr_t) &sqlite3_bind_text);
|
||||
uuid_t controller_id;
|
||||
if(uuid_parse(controller_id_str.c_str(), controller_id))
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k400BadRequest);
|
||||
callback(resp);
|
||||
return;
|
||||
}
|
||||
controller_dbo **controllers = controller_dbo::get_by_simple("id", controller_id, (intptr_t) &sqlite3_bind_blob, sizeof(uuid_t));
|
||||
|
||||
if(controllers[0])
|
||||
{
|
||||
|
@ -92,11 +108,19 @@ controllers::delete_one_by_id(const HttpRequestPtr &req, std::function<void(cons
|
|||
|
||||
void
|
||||
controllers::put_one_by_id(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback,
|
||||
const std::string &controller_id)
|
||||
const std::string &controller_id_str)
|
||||
{
|
||||
Json::Value body = *req->getJsonObject();
|
||||
|
||||
controller_dbo **controllers = controller_dbo::get_by_simple("id", controller_id.c_str(), (intptr_t) &sqlite3_bind_text);
|
||||
uuid_t controller_id;
|
||||
if(uuid_parse(controller_id_str.c_str(), controller_id))
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k400BadRequest);
|
||||
callback(resp);
|
||||
return;
|
||||
}
|
||||
controller_dbo **controllers = controller_dbo::get_by_simple("id", controller_id, (intptr_t) &sqlite3_bind_blob, sizeof(uuid_t));
|
||||
|
||||
if(controllers[0])
|
||||
{
|
||||
|
|
|
@ -21,13 +21,13 @@ namespace api::v1
|
|||
|
||||
static void post_discover(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback);
|
||||
static void get_all(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback);
|
||||
static void get_one_by_id(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback, const std::string& controller_id);
|
||||
static void get_one_by_id(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback, const std::string& controller_id_str);
|
||||
static void get_one_by_tag(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback, const std::string& controller_tag);
|
||||
static void delete_one_by_id(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback, const std::string& controller_id);
|
||||
static void delete_one_by_id(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback, const std::string& controller_id_str);
|
||||
static void put_one_by_id(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback, const std::string& controller_id);
|
||||
|
||||
static void get_relays_all(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback, const std::string& controller_id);
|
||||
static void get_relays_one_by_id_and_num(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback, const std::string& controller_id, int relay_num);
|
||||
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);
|
||||
static void get_relays_all(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback, const std::string& controller_id_str);
|
||||
static void get_relays_one_by_id_and_num(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback, const std::string& controller_id_str, int relay_num);
|
||||
static void put_relays_one_by_id_and_num(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback, const std::string& controller_id_str, int relay_num);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -11,6 +11,14 @@
|
|||
|
||||
using namespace api::v1;
|
||||
|
||||
enum DISCOVERY_MAPPING
|
||||
{
|
||||
DISCOVERY_MAPPING_ID = 0,
|
||||
DISCOVERY_MAPPING_NAME = 1,
|
||||
DISCOVERY_MAPPING_COMMAND_PORT = 2,
|
||||
DISCOVERY_MAPPING_RELAY_COUNT = 3,
|
||||
};
|
||||
|
||||
void controllers::post_discover(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback)
|
||||
{
|
||||
|
||||
|
@ -95,12 +103,13 @@ void controllers::post_discover(const HttpRequestPtr &req, std::function<void(co
|
|||
continue;
|
||||
}
|
||||
|
||||
uuid_t uuid;
|
||||
int uuid_size = sizeof(uuid_t);
|
||||
memcpy(&uuid, binn_object_blob(answer_payload, "uuid", &uuid_size), uuid_size);
|
||||
uuid_t discovered_id;
|
||||
int id_size = sizeof(uuid_t);
|
||||
memcpy(&discovered_id, binn_map_blob(answer_payload, DISCOVERY_MAPPING_ID, &id_size), id_size);
|
||||
//strncpy(&id, binn_map_blob(answer_payload, DISCOVERY_MAPPING_ID, &uuid_size), uuid_size);
|
||||
|
||||
char uuid_str[38];
|
||||
uuid_unparse(uuid, uuid_str);
|
||||
uuid_unparse(discovered_id, uuid_str);
|
||||
LOG_DEBUG << uuid_str;
|
||||
continue;
|
||||
|
||||
|
@ -108,15 +117,13 @@ void controllers::post_discover(const HttpRequestPtr &req, std::function<void(co
|
|||
|
||||
Json::Value client_info;
|
||||
|
||||
const char *discovered_id = client_info["id"].asCString();
|
||||
|
||||
bool found_discovered_in_list = false;
|
||||
|
||||
for(int i = 0; known_controllers[i] != nullptr; i++)
|
||||
{
|
||||
if(!found_discovered_in_list)
|
||||
{
|
||||
if(strcmp(known_controllers[i]->id, discovered_id) == 0)
|
||||
if(uuid_compare(known_controllers[i]->id, discovered_id) == 0)
|
||||
{
|
||||
known_controllers[i]->active = true;
|
||||
known_controllers[i]->update();
|
||||
|
@ -135,7 +142,7 @@ void controllers::post_discover(const HttpRequestPtr &req, std::function<void(co
|
|||
{
|
||||
controller_dbo discovered_controller{};
|
||||
strcpy(discovered_controller.ip, inet_ntoa(addr.sin_addr));
|
||||
strcpy(discovered_controller.id, discovered_id);
|
||||
memcpy(discovered_controller.id, discovered_id, sizeof(uuid_t));
|
||||
strcpy(discovered_controller.name, client_info["name"].asCString());
|
||||
discovered_controller.relay_count = client_info["relay_count"].asInt();
|
||||
discovered_controller.port = client_info["port"].asInt();
|
||||
|
|
|
@ -10,9 +10,17 @@ using namespace api::v1;
|
|||
|
||||
void
|
||||
controllers::get_relays_all(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback,
|
||||
const std::string& controller_id)
|
||||
const std::string& controller_id_str)
|
||||
{
|
||||
relay_dbo **all_controller_relays = relay_dbo::get_by_simple("controller_id", (void *) controller_id.c_str(), (intptr_t) sqlite3_bind_text);
|
||||
uuid_t controller_id;
|
||||
if(uuid_parse(controller_id_str.c_str(), controller_id))
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k400BadRequest);
|
||||
callback(resp);
|
||||
return;
|
||||
}
|
||||
relay_dbo **all_controller_relays = relay_dbo::get_by_simple("controller_id", (void *) controller_id, (intptr_t) sqlite3_bind_blob, sizeof(uuid_t));
|
||||
Json::Value all_relays_json(Json::arrayValue);
|
||||
|
||||
for(int i = 0; all_controller_relays[i] != nullptr; i++)
|
||||
|
@ -29,10 +37,18 @@ controllers::get_relays_all(const HttpRequestPtr &req, std::function<void(const
|
|||
|
||||
void
|
||||
controllers::get_relays_one_by_id_and_num(const HttpRequestPtr &req,
|
||||
std::function<void(const HttpResponsePtr &)> &&callback, const std::string& controller_id,
|
||||
std::function<void(const HttpResponsePtr &)> &&callback, const std::string& controller_id_str,
|
||||
int relay_num)
|
||||
{
|
||||
relay_dbo *relay = relay_dbo::get_relay_for_controller(controller_id.c_str(), relay_num);
|
||||
uuid_t controller_id;
|
||||
if(uuid_parse(controller_id_str.c_str(), controller_id))
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k400BadRequest);
|
||||
callback(resp);
|
||||
return;
|
||||
}
|
||||
relay_dbo *relay = relay_dbo::get_relay_for_controller(controller_id, relay_num);
|
||||
|
||||
if(relay)
|
||||
{
|
||||
|
@ -53,10 +69,18 @@ controllers::get_relays_one_by_id_and_num(const HttpRequestPtr &req,
|
|||
|
||||
void
|
||||
controllers::put_relays_one_by_id_and_num(const HttpRequestPtr &req,
|
||||
std::function<void(const HttpResponsePtr &)> &&callback, const std::string& controller_id,
|
||||
std::function<void(const HttpResponsePtr &)> &&callback, const std::string& controller_id_str,
|
||||
int relay_num)
|
||||
{
|
||||
if(!relay_dbo::valid_num_for_controller(controller_id.c_str(), relay_num))
|
||||
uuid_t controller_id;
|
||||
if(uuid_parse(controller_id_str.c_str(), controller_id))
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k400BadRequest);
|
||||
callback(resp);
|
||||
return;
|
||||
}
|
||||
if(!relay_dbo::valid_num_for_controller(controller_id, relay_num))
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k400BadRequest);
|
||||
|
@ -64,15 +88,24 @@ controllers::put_relays_one_by_id_and_num(const HttpRequestPtr &req,
|
|||
return;
|
||||
}
|
||||
|
||||
relay_dbo *relay = relay_dbo::get_relay_for_controller(controller_id.c_str(), relay_num);
|
||||
Json::Value body = *req->getJsonObject();
|
||||
uuid_t active_schedule_id;
|
||||
if(!schedule_dbo::parse_id(body["active_schedule"].asCString(), active_schedule_id))
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k400BadRequest);
|
||||
callback(resp);
|
||||
return;
|
||||
}
|
||||
|
||||
relay_dbo *relay = relay_dbo::get_relay_for_controller(controller_id, relay_num);
|
||||
|
||||
bool db_action_result;
|
||||
|
||||
if(relay)
|
||||
{
|
||||
strncpy(relay->name, body["name"].asCString(), 127);
|
||||
strncpy(relay->active_schedule_id, body["active_schedule"].asCString(), 32);
|
||||
uuid_copy(relay->active_schedule_id, active_schedule_id);
|
||||
|
||||
db_action_result = relay->update();
|
||||
}
|
||||
|
@ -81,8 +114,9 @@ controllers::put_relays_one_by_id_and_num(const HttpRequestPtr &req,
|
|||
relay = new relay_dbo();
|
||||
relay->number = relay_num;
|
||||
strncpy(relay->name, body["name"].asCString(), 127);
|
||||
strncpy(relay->active_schedule_id, body["active_schedule"].asCString(), 32);
|
||||
strncpy(relay->controller_id, controller_id.c_str(), 32);
|
||||
|
||||
uuid_copy(relay->active_schedule_id, active_schedule_id);
|
||||
uuid_copy(relay->controller_id, controller_id);
|
||||
|
||||
relay->reload_active_schedule();
|
||||
|
||||
|
@ -97,8 +131,8 @@ controllers::put_relays_one_by_id_and_num(const HttpRequestPtr &req,
|
|||
}
|
||||
else
|
||||
{
|
||||
auto schedules = schedule_dbo::get_by_simple("id", body["active_schedule"].asCString(), (intptr_t)&sqlite3_bind_text);
|
||||
auto controllers = controller_dbo::get_by_simple("id", controller_id.c_str(), (intptr_t)&sqlite3_bind_text);
|
||||
auto schedules = schedule_dbo::get_by_simple("id", active_schedule_id, (intptr_t)&sqlite3_bind_blob, sizeof(uuid_t));
|
||||
auto controllers = controller_dbo::get_by_simple("id", controller_id, (intptr_t)&sqlite3_bind_blob, sizeof(uuid_t));
|
||||
|
||||
Json::Value payload;
|
||||
payload["target"] = relay_num;
|
||||
|
|
|
@ -26,7 +26,7 @@ void
|
|||
relays::get_one_by_tag(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback,
|
||||
const std::string &relay_tag)
|
||||
{
|
||||
relay_dbo **relays = relay_dbo::get_by_simple("tag", relay_tag.c_str(), (intptr_t)&sqlite3_bind_text);
|
||||
relay_dbo **relays = relay_dbo::get_by_simple("tag", relay_tag.c_str(), (intptr_t)&sqlite3_bind_text, -1);
|
||||
|
||||
if(relays[0])
|
||||
{
|
||||
|
|
|
@ -25,9 +25,18 @@ schedules::get_all(const HttpRequestPtr &req, std::function<void(const HttpRespo
|
|||
}
|
||||
|
||||
void
|
||||
schedules::get_one_by_id(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback, const std::string& schedule_id)
|
||||
schedules::get_one_by_id(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback, const std::string& schedule_id_str)
|
||||
{
|
||||
schedule_dbo **schedules = schedule_dbo::get_by_simple("id", schedule_id.c_str(), (intptr_t) &sqlite3_bind_text);
|
||||
uuid_t schedule_id;
|
||||
if(schedule_dbo::parse_id(schedule_id_str.c_str(), schedule_id))
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k400BadRequest);
|
||||
callback(resp);
|
||||
return;
|
||||
}
|
||||
|
||||
schedule_dbo **schedules = schedule_dbo::get_by_simple("id", schedule_id, (intptr_t) &sqlite3_bind_blob, sizeof(uuid_t));
|
||||
|
||||
if(schedules[0])
|
||||
{
|
||||
|
@ -46,9 +55,9 @@ schedules::get_one_by_id(const HttpRequestPtr &req, std::function<void(const Htt
|
|||
}
|
||||
|
||||
void
|
||||
schedules::delete_one_by_id(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback, const std::string& schedule_id)
|
||||
schedules::delete_one_by_id(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback, const std::string& schedule_id_str)
|
||||
{
|
||||
if(strcmp(schedule_id.c_str(), "off") == 0 || strcmp(schedule_id.c_str(), "on") == 0)
|
||||
if(strcmp(schedule_id_str.c_str(), "off") == 0 || strcmp(schedule_id_str.c_str(), "on") == 0)
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k403Forbidden);
|
||||
|
@ -57,7 +66,15 @@ schedules::delete_one_by_id(const HttpRequestPtr &req, std::function<void(const
|
|||
return;
|
||||
}
|
||||
|
||||
schedule_dbo **schedules = schedule_dbo::get_by_simple("id", schedule_id.c_str(), (intptr_t) &sqlite3_bind_text);
|
||||
uuid_t schedule_id;
|
||||
if(schedule_dbo::parse_id(schedule_id_str.c_str(), schedule_id))
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k400BadRequest);
|
||||
callback(resp);
|
||||
return;
|
||||
}
|
||||
schedule_dbo **schedules = schedule_dbo::get_by_simple("id", schedule_id, (intptr_t) &sqlite3_bind_blob, sizeof(uuid_t));
|
||||
|
||||
if(schedules[0])
|
||||
{
|
||||
|
@ -88,7 +105,7 @@ schedules::post_new(const HttpRequestPtr &req, std::function<void(const HttpResp
|
|||
|
||||
strncpy(new_schedule.name, body["name"].asCString(), 127);
|
||||
new_schedule.name[127] = '\0';
|
||||
strncpy(new_schedule.id, drogon::utils::getUuid().c_str(), 32);
|
||||
uuid_generate(new_schedule.id);
|
||||
new_schedule.id[32] = '\0';
|
||||
new_schedule.periods = helpers::parse_periods(body["periods"]);
|
||||
|
||||
|
@ -107,9 +124,9 @@ schedules::post_new(const HttpRequestPtr &req, std::function<void(const HttpResp
|
|||
|
||||
void
|
||||
schedules::put_one_by_id(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback,
|
||||
const std::string &schedule_id)
|
||||
const std::string &schedule_id_str)
|
||||
{
|
||||
if(strcmp(schedule_id.c_str(), "off") == 0 || strcmp(schedule_id.c_str(), "on") == 0)
|
||||
if(strcmp(schedule_id_str.c_str(), "off") == 0 || strcmp(schedule_id_str.c_str(), "on") == 0)
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k403Forbidden);
|
||||
|
@ -118,9 +135,17 @@ schedules::put_one_by_id(const HttpRequestPtr &req, std::function<void(const Htt
|
|||
return;
|
||||
}
|
||||
|
||||
Json::Value body = *req->jsonObject();
|
||||
uuid_t schedule_id;
|
||||
if(schedule_dbo::parse_id(schedule_id_str.c_str(), schedule_id))
|
||||
{
|
||||
auto resp = HttpResponse::newHttpResponse();
|
||||
resp->setStatusCode(k400BadRequest);
|
||||
callback(resp);
|
||||
return;
|
||||
}
|
||||
schedule_dbo **schedules = schedule_dbo::get_by_simple("id", schedule_id, (intptr_t) &sqlite3_bind_blob, sizeof(uuid_t));
|
||||
|
||||
schedule_dbo **schedules = schedule_dbo::get_by_simple("id", schedule_id.c_str(), (intptr_t) &sqlite3_bind_text);
|
||||
Json::Value body = *req->jsonObject();
|
||||
|
||||
if(schedules[0])
|
||||
{
|
||||
|
|
|
@ -21,9 +21,17 @@ void valid_json::doFilter(const HttpRequestPtr &req,
|
|||
is_valid &= body["name"].type() == Json::ValueType::stringValue;
|
||||
is_valid &= body["active_schedule"].type() == Json::ValueType::stringValue;
|
||||
|
||||
uuid_t active_schedule_id;
|
||||
if(schedule_dbo::parse_id(body["active_schedule"].asCString(), active_schedule_id))
|
||||
{
|
||||
auto res = drogon::HttpResponse::newHttpResponse();
|
||||
res->setStatusCode(k400BadRequest);
|
||||
fcb(res);
|
||||
}
|
||||
|
||||
if(is_valid)
|
||||
{
|
||||
schedule_dbo **schedules = schedule_dbo::get_by_simple("id", body["active_schedule"].asCString(), (intptr_t)&sqlite3_bind_text);
|
||||
schedule_dbo **schedules = schedule_dbo::get_by_simple("id", active_schedule_id, (intptr_t)&sqlite3_bind_blob, sizeof(uuid_t));
|
||||
bool schedule_found = schedules[0] != nullptr;
|
||||
schedule_dbo::free_list(schedules);
|
||||
if(schedule_found)
|
||||
|
|
|
@ -22,11 +22,12 @@ namespace helpers
|
|||
|
||||
typedef struct sql_filter_builder
|
||||
{
|
||||
sql_filter_builder(const char *col_name, const void *value, intptr_t bind_func, const char *logic);
|
||||
sql_filter_builder(const char *col_name, const void *value, intptr_t bind_func, int bind_func_param, const char *logic);
|
||||
|
||||
const char *col_name;
|
||||
const void *value;
|
||||
intptr_t bind_func;
|
||||
int bind_func_param;
|
||||
const char *logic;
|
||||
} sql_filter_builder;
|
||||
|
||||
|
|
|
@ -41,18 +41,22 @@ helpers::create_sql_filtered_query(const char *sql, sql_filter_builder **filters
|
|||
}
|
||||
if(filter->bind_func == (intptr_t)&sqlite3_bind_text)
|
||||
{
|
||||
sqlite3_bind_text(stmt, i + 1, (char*)filter->value, -1, SQLITE_STATIC);
|
||||
sqlite3_bind_text(stmt, i + 1, (char*)filter->value, filter->bind_func_param, SQLITE_STATIC);
|
||||
}
|
||||
if(filter->bind_func == (intptr_t)&sqlite3_bind_blob)
|
||||
{
|
||||
sqlite3_bind_blob(stmt, i + 1, filter->value, filter->bind_func_param, SQLITE_STATIC);
|
||||
}
|
||||
}
|
||||
|
||||
return stmt;
|
||||
}
|
||||
|
||||
helpers::sql_filter_builder::sql_filter_builder(const char *col_name, const void *value, intptr_t bind_func,
|
||||
const char *logic)
|
||||
helpers::sql_filter_builder::sql_filter_builder(const char *col_name, const void *value, intptr_t bind_func, int bind_func_param, const char *logic)
|
||||
{
|
||||
this->col_name = col_name;
|
||||
this->value = value;
|
||||
this->bind_func = bind_func;
|
||||
this->bind_func_param = bind_func_param;
|
||||
this->logic = logic;
|
||||
}
|
|
@ -1,11 +1,12 @@
|
|||
#include <helpers.h>
|
||||
#include <globals.h>
|
||||
#include <uuid/uuid.h>
|
||||
#include <drogon/trantor/trantor/utils/Logger.h>
|
||||
#include <drogon/utils/Utilities.h>
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <sql/migration_0.h>
|
||||
#include <sql/migration_1.h>
|
||||
|
||||
int
|
||||
helpers::migrate_sql()
|
||||
|
@ -41,15 +42,6 @@ helpers::migrate_sql()
|
|||
break;
|
||||
}
|
||||
new_version_num = 1;
|
||||
case 1:
|
||||
LOG_INFO << "Migrating LEVEL 1";
|
||||
rc = sqlite3_exec(globals::db, (const char *)sql_migration_1_sql, nullptr, nullptr, &err_msg);
|
||||
if(rc != 0)
|
||||
{
|
||||
LOG_FATAL << "Couldn't migrate LEVEL 1 (" << err_msg << ")";
|
||||
break;
|
||||
}
|
||||
new_version_num = 2;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <trantor/utils/Logger.h>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#include <uuid/uuid.h>
|
||||
#include <helpers.h>
|
||||
#include "controller_dbo.h"
|
||||
#include "globals.h"
|
||||
|
@ -19,7 +20,7 @@ static bool controller_db_update_insert(controller_dbo *controller, sqlite3_stmt
|
|||
{
|
||||
int rc;
|
||||
|
||||
sqlite3_bind_text(stmt, 1, controller->id, -1, SQLITE_STATIC);
|
||||
sqlite3_bind_blob(stmt, 1, controller->id, sizeof(uuid_t), SQLITE_STATIC);
|
||||
sqlite3_bind_text(stmt, 2, controller->name, -1, SQLITE_STATIC);
|
||||
sqlite3_bind_text(stmt, 3, controller->ip, -1, SQLITE_STATIC);
|
||||
sqlite3_bind_int(stmt, 4, controller->active);
|
||||
|
@ -56,7 +57,7 @@ controller_db_select_mapper(sqlite3_stmt *stmt)
|
|||
switch(name[1])
|
||||
{
|
||||
case 'd': // id
|
||||
strncpy(new_controller->id, (const char*)sqlite3_column_text(stmt, i), 32);
|
||||
uuid_copy(new_controller->id, (const unsigned char*)sqlite3_column_blob(stmt, i));
|
||||
break;
|
||||
case 'p': // ip
|
||||
strncpy(new_controller->ip, (const char*)sqlite3_column_text(stmt, i), 16);
|
||||
|
@ -104,7 +105,7 @@ controller_db_select(sqlite3_stmt *stmt)
|
|||
if (s == SQLITE_ROW)
|
||||
{
|
||||
controller_dbo *new_controller = controller_db_select_mapper(stmt);
|
||||
new_controller->relays = relay_dbo::get_by_simple("controller_id", new_controller->id, (intptr_t)&sqlite3_bind_text);
|
||||
new_controller->relays = relay_dbo::get_by_simple("controller_id", new_controller->id, (intptr_t)&sqlite3_bind_blob, sizeof(uuid_t));
|
||||
row++;
|
||||
|
||||
all_controllers = (controller_dbo**)realloc(all_controllers, sizeof(controller_dbo*) * (row + 1));
|
||||
|
@ -158,7 +159,7 @@ controller_dbo::remove()
|
|||
int rc;
|
||||
|
||||
sqlite3_prepare_v2(globals::db, "DELETE FROM controllers WHERE id=?1;", -1, &stmt, nullptr);
|
||||
sqlite3_bind_text(stmt, 1, this->id, -1, SQLITE_STATIC);
|
||||
sqlite3_bind_blob(stmt, 1, this->id, sizeof(uuid_t), SQLITE_STATIC);
|
||||
rc = sqlite3_step(stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
|
||||
|
@ -169,9 +170,11 @@ controller_dbo::remove()
|
|||
Json::Value
|
||||
controller_dbo::to_json()
|
||||
{
|
||||
char id_str[37];
|
||||
uuid_unparse(this->id, id_str);
|
||||
Json::Value controller_json;
|
||||
controller_json["name"] = this->name;
|
||||
controller_json["id"] = this->id;
|
||||
controller_json["id"] = id_str;
|
||||
controller_json["ip"] = this->ip;
|
||||
controller_json["relay_count"] = this->relay_count;
|
||||
controller_json["active"] = this->active;
|
||||
|
@ -199,7 +202,7 @@ controller_dbo::get_all()
|
|||
}
|
||||
|
||||
controller_dbo**
|
||||
controller_dbo::get_by_simple(const char *key, const void *value, intptr_t bind_func)
|
||||
controller_dbo::get_by_simple(const char *key, const void *value, intptr_t bind_func, int bind_func_param)
|
||||
{
|
||||
helpers::sql_filter_builder *filters[1];
|
||||
helpers::sql_filter_builder filter
|
||||
|
@ -207,6 +210,7 @@ controller_dbo::get_by_simple(const char *key, const void *value, intptr_t bind_
|
|||
key,
|
||||
value,
|
||||
bind_func,
|
||||
bind_func_param,
|
||||
";"
|
||||
};
|
||||
filters[0] = &filter;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define EMGAUWA_CORE_controller_DBO_H
|
||||
|
||||
#include <string>
|
||||
#include <uuid/uuid.h>
|
||||
#include <sqlite3.h>
|
||||
#include <json/value.h>
|
||||
#include <helpers.h>
|
||||
|
@ -11,7 +12,7 @@ class controller_dbo
|
|||
{
|
||||
public:
|
||||
|
||||
char id[33];
|
||||
uuid_t id;
|
||||
char name[128];
|
||||
char ip[17];
|
||||
bool active;
|
||||
|
@ -35,7 +36,7 @@ public:
|
|||
to_json();
|
||||
|
||||
static controller_dbo**
|
||||
get_by_simple(const char *key, const void *value, intptr_t bind_func);
|
||||
get_by_simple(const char *key, const void *value, intptr_t bind_func, int bind_func_param);
|
||||
|
||||
static controller_dbo**
|
||||
get_by(helpers::sql_filter_builder **filters);
|
||||
|
|
|
@ -14,8 +14,8 @@ static bool relay_db_update_insert(relay_dbo *relay, sqlite3_stmt *stmt)
|
|||
sqlite3_bind_int(stmt, 1, relay->id);
|
||||
sqlite3_bind_int(stmt, 2, relay->number);
|
||||
sqlite3_bind_text(stmt, 3, relay->name, -1, SQLITE_STATIC);
|
||||
sqlite3_bind_text(stmt, 4, relay->active_schedule_id, -1, SQLITE_STATIC);
|
||||
sqlite3_bind_text(stmt, 5, relay->controller_id, -1, SQLITE_STATIC);
|
||||
sqlite3_bind_blob(stmt, 4, relay->active_schedule_id, sizeof(uuid_t), SQLITE_STATIC);
|
||||
sqlite3_bind_blob(stmt, 5, relay->controller_id, sizeof(uuid_t), SQLITE_STATIC);
|
||||
sqlite3_bind_text(stmt, 6, relay->tag, -1, SQLITE_STATIC);
|
||||
|
||||
rc = sqlite3_step(stmt);
|
||||
|
@ -41,10 +41,10 @@ relay_db_select_mapper(sqlite3_stmt *stmt)
|
|||
switch(name[0])
|
||||
{
|
||||
case 'a': // active_schedule_id
|
||||
strncpy(new_relay->active_schedule_id, (const char*)sqlite3_column_text(stmt, i), 32);
|
||||
uuid_copy(new_relay->active_schedule_id, (const unsigned char*)sqlite3_column_blob(stmt, i));
|
||||
break;
|
||||
case 'c': // controller_id
|
||||
strncpy(new_relay->controller_id, (const char*)sqlite3_column_text(stmt, i), 32);
|
||||
uuid_copy(new_relay->controller_id, (const unsigned char*)sqlite3_column_blob(stmt, i));
|
||||
break;
|
||||
case 'i':
|
||||
new_relay->id = sqlite3_column_int(stmt, i);
|
||||
|
@ -123,13 +123,16 @@ relay_db_select(sqlite3_stmt *stmt)
|
|||
void
|
||||
relay_dbo::reload_active_schedule()
|
||||
{
|
||||
schedule_dbo **schedules = schedule_dbo::get_by_simple("id", this->active_schedule_id, (intptr_t)&sqlite3_bind_text);
|
||||
schedule_dbo **schedules = schedule_dbo::get_by_simple("id", this->active_schedule_id, (intptr_t)&sqlite3_bind_blob, sizeof(uuid_t));
|
||||
|
||||
if(!schedules[0])
|
||||
{
|
||||
free(schedules);
|
||||
schedules = schedule_dbo::get_by_simple("id", "off", (intptr_t)&sqlite3_bind_text);
|
||||
strcpy(this->active_schedule_id, "off");
|
||||
uuid_t off_uuid;
|
||||
memset(off_uuid, 0, sizeof(uuid_t));
|
||||
memcpy(off_uuid, "off", 3);
|
||||
schedules = schedule_dbo::get_by_simple("id", off_uuid, (intptr_t)&sqlite3_bind_blob, sizeof(uuid_t));
|
||||
uuid_copy(this->active_schedule_id, off_uuid);
|
||||
}
|
||||
|
||||
this->active_schedule = schedules[0];
|
||||
|
@ -175,11 +178,15 @@ relay_dbo::remove()
|
|||
Json::Value
|
||||
relay_dbo::to_json()
|
||||
{
|
||||
char controller_id_str[37];
|
||||
uuid_unparse(this->controller_id, controller_id_str);
|
||||
char active_schedule_id_str[37];
|
||||
uuid_unparse(this->active_schedule_id, active_schedule_id_str);
|
||||
Json::Value relay_json;
|
||||
relay_json["name"] = this->name;
|
||||
relay_json["number"] = this->number;
|
||||
relay_json["active_schedule_id"] = this->active_schedule_id;
|
||||
relay_json["controller_id"] = this->controller_id;
|
||||
relay_json["active_schedule_id"] = active_schedule_id_str;
|
||||
relay_json["controller_id"] = controller_id_str;
|
||||
relay_json["active_schedule"] = this->active_schedule->to_json();
|
||||
relay_json["tag"] = this->tag;
|
||||
|
||||
|
@ -197,7 +204,7 @@ relay_dbo::get_all()
|
|||
}
|
||||
|
||||
relay_dbo**
|
||||
relay_dbo::get_by_simple(const char *key, const void *value, intptr_t bind_func)
|
||||
relay_dbo::get_by_simple(const char *key, const void *value, intptr_t bind_func, int bind_func_param)
|
||||
{
|
||||
helpers::sql_filter_builder *filters[1];
|
||||
helpers::sql_filter_builder filter
|
||||
|
@ -205,6 +212,7 @@ relay_dbo::get_by_simple(const char *key, const void *value, intptr_t bind_func)
|
|||
key,
|
||||
value,
|
||||
bind_func,
|
||||
bind_func_param,
|
||||
";"
|
||||
};
|
||||
filters[0] = &filter;
|
||||
|
@ -221,19 +229,21 @@ relay_dbo::get_by(helpers::sql_filter_builder **filters)
|
|||
}
|
||||
|
||||
relay_dbo*
|
||||
relay_dbo::get_relay_for_controller(const char *controller_id, int relay_num)
|
||||
relay_dbo::get_relay_for_controller(uuid_t controller_id, int relay_num)
|
||||
{
|
||||
helpers::sql_filter_builder *filters[2];
|
||||
helpers::sql_filter_builder filter(
|
||||
"number",
|
||||
(void*)(intptr_t)relay_num,
|
||||
(intptr_t)&sqlite3_bind_int,
|
||||
0,
|
||||
"AND"
|
||||
);
|
||||
helpers::sql_filter_builder filter2(
|
||||
"controller_id",
|
||||
(void*)controller_id,
|
||||
(intptr_t)sqlite3_bind_text,
|
||||
(intptr_t)sqlite3_bind_blob,
|
||||
sizeof(uuid_t),
|
||||
";"
|
||||
);
|
||||
filters[0] = &filter;
|
||||
|
@ -247,9 +257,9 @@ relay_dbo::get_relay_for_controller(const char *controller_id, int relay_num)
|
|||
}
|
||||
|
||||
bool
|
||||
relay_dbo::valid_num_for_controller(const char *search_controller_id, int relay_num)
|
||||
relay_dbo::valid_num_for_controller(uuid_t search_controller_id, int relay_num)
|
||||
{
|
||||
controller_dbo **controllers = controller_dbo::get_by_simple("id", search_controller_id, (intptr_t)&sqlite3_bind_text);
|
||||
controller_dbo **controllers = controller_dbo::get_by_simple("id", search_controller_id, (intptr_t)&sqlite3_bind_blob, sizeof(uuid_t));
|
||||
|
||||
bool valid_id_and_num = controllers[0] && controllers[0]->relay_count > relay_num;
|
||||
controller_dbo::free_list(controllers);
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <string>
|
||||
#include <sqlite3.h>
|
||||
#include <json/value.h>
|
||||
#include <uuid/uuid.h>
|
||||
#include <helpers.h>
|
||||
#include "schedule_dbo.h"
|
||||
|
||||
|
@ -14,8 +15,8 @@ public:
|
|||
int id;
|
||||
char name[128];
|
||||
int number;
|
||||
char controller_id[33];
|
||||
char active_schedule_id[33];
|
||||
uuid_t controller_id;
|
||||
uuid_t active_schedule_id;
|
||||
char tag[64];
|
||||
schedule_dbo *active_schedule;
|
||||
|
||||
|
@ -38,16 +39,16 @@ public:
|
|||
free_list(relay_dbo **relays_list);
|
||||
|
||||
static relay_dbo**
|
||||
get_by_simple(const char *key, const void *value, intptr_t bind_func);
|
||||
get_by_simple(const char *key, const void *value, intptr_t bind_func, int bind_func_param);
|
||||
|
||||
static relay_dbo**
|
||||
get_by(helpers::sql_filter_builder **filters);
|
||||
|
||||
static relay_dbo*
|
||||
get_relay_for_controller(const char *controller_id, int relay_num);
|
||||
get_relay_for_controller(uuid_t controller_id, int relay_num);
|
||||
|
||||
static bool
|
||||
valid_num_for_controller(const char *search_controller_id, int relay_num);
|
||||
valid_num_for_controller(uuid_t search_controller_id, int relay_num);
|
||||
|
||||
static relay_dbo**
|
||||
get_all();
|
||||
|
|
|
@ -11,7 +11,7 @@ static bool schedule_db_update_insert(schedule_dbo *schedule, sqlite3_stmt *stmt
|
|||
uint16_t *periods_blob = schedule->periods->to_db_blob();
|
||||
int blob_size = (int)sizeof(uint16_t) * ((periods_blob[0] * 2) + 1);
|
||||
|
||||
sqlite3_bind_text(stmt, 1, schedule->id, -1, SQLITE_STATIC);
|
||||
sqlite3_bind_blob(stmt, 1, schedule->id, sizeof(uuid_t), SQLITE_STATIC);
|
||||
sqlite3_bind_text(stmt, 2, schedule->name, -1, SQLITE_STATIC);
|
||||
sqlite3_bind_blob(stmt, 3, periods_blob, blob_size, SQLITE_STATIC);
|
||||
|
||||
|
@ -39,8 +39,7 @@ schedule_db_select_mapper(sqlite3_stmt *stmt)
|
|||
switch(name[0])
|
||||
{
|
||||
case 'i': // id
|
||||
strncpy(new_schedule->id, (const char*)sqlite3_column_text(stmt, i), 32);
|
||||
new_schedule->id[32] = '\0';
|
||||
uuid_copy(new_schedule->id, (const unsigned char*)sqlite3_column_blob(stmt, i));
|
||||
break;
|
||||
case 'n': // name
|
||||
strncpy(new_schedule->name, (const char*)sqlite3_column_text(stmt, i), 127);
|
||||
|
@ -124,7 +123,7 @@ schedule_dbo::remove()
|
|||
int rc;
|
||||
|
||||
sqlite3_prepare_v2(globals::db, "DELETE FROM schedules WHERE id=?1;", -1, &stmt, nullptr);
|
||||
sqlite3_bind_text(stmt, 1, this->id, -1, SQLITE_STATIC);
|
||||
sqlite3_bind_blob(stmt, 1, this->id, sizeof(uuid_t), SQLITE_STATIC);
|
||||
rc = sqlite3_step(stmt);
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
|
@ -141,9 +140,11 @@ schedule_dbo::~schedule_dbo()
|
|||
Json::Value
|
||||
schedule_dbo::to_json()
|
||||
{
|
||||
char id_str[37];
|
||||
schedule_dbo::unparse_id(this->id, id_str);
|
||||
Json::Value schedule_json;
|
||||
schedule_json["name"] = this->name;
|
||||
schedule_json["id"] = this->id;
|
||||
schedule_json["id"] = id_str;
|
||||
schedule_json["periods"] = this->periods->to_json();
|
||||
|
||||
return schedule_json;
|
||||
|
@ -160,7 +161,7 @@ schedule_dbo::get_all()
|
|||
}
|
||||
|
||||
schedule_dbo**
|
||||
schedule_dbo::get_by_simple(const char *key, const void *value, intptr_t bind_func)
|
||||
schedule_dbo::get_by_simple(const char *key, const void *value, intptr_t bind_func, int bind_func_param)
|
||||
{
|
||||
helpers::sql_filter_builder *filters[1];
|
||||
helpers::sql_filter_builder filter
|
||||
|
@ -168,6 +169,7 @@ schedule_dbo::get_by_simple(const char *key, const void *value, intptr_t bind_fu
|
|||
key,
|
||||
value,
|
||||
bind_func,
|
||||
bind_func_param,
|
||||
";"
|
||||
};
|
||||
filters[0] = &filter;
|
||||
|
@ -195,3 +197,49 @@ schedule_dbo::free_list(schedule_dbo **schedules_list)
|
|||
free(schedules_list);
|
||||
}
|
||||
|
||||
int
|
||||
schedule_dbo::parse_id(const char *id_str, uuid_t result)
|
||||
{
|
||||
if(strcmp("off", id_str) == 0)
|
||||
{
|
||||
memset(result, 0, sizeof(uuid_t));
|
||||
memcpy(result, "off", 3);
|
||||
return 0;
|
||||
}
|
||||
if(strcmp("on", id_str) == 0)
|
||||
{
|
||||
memset(result, 0, sizeof(uuid_t));
|
||||
memcpy(result, "on", 2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(uuid_parse(id_str, result))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
schedule_dbo::unparse_id(const uuid_t id, char *result)
|
||||
{
|
||||
uuid_t tmp_uuid;
|
||||
|
||||
memset(tmp_uuid, 0, sizeof(uuid_t));
|
||||
memcpy(tmp_uuid, "off", 3);
|
||||
if(uuid_compare(id, tmp_uuid) == 0)
|
||||
{
|
||||
strcpy(result, "off");
|
||||
return;
|
||||
}
|
||||
|
||||
memset(tmp_uuid, 0, sizeof(uuid_t));
|
||||
memcpy(tmp_uuid, "on", 2);
|
||||
if(uuid_compare(id, tmp_uuid) == 0)
|
||||
{
|
||||
strcpy(result, "on");
|
||||
return;
|
||||
}
|
||||
|
||||
uuid_unparse(id, result);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <string>
|
||||
#include <sqlite3.h>
|
||||
#include <uuid/uuid.h>
|
||||
#include <json/value.h>
|
||||
#include <helpers.h>
|
||||
#include "period.h"
|
||||
|
@ -12,7 +13,7 @@ class schedule_dbo
|
|||
{
|
||||
public:
|
||||
|
||||
char id[33];
|
||||
uuid_t id;
|
||||
char name[128];
|
||||
period_list *periods;
|
||||
|
||||
|
@ -34,13 +35,19 @@ public:
|
|||
free_list(schedule_dbo **schedules_list);
|
||||
|
||||
static schedule_dbo**
|
||||
get_by_simple(const char *key, const void *value, intptr_t bind_func);
|
||||
get_by_simple(const char *key, const void *value, intptr_t bind_func, int bind_func_param);
|
||||
|
||||
static schedule_dbo**
|
||||
get_by(helpers::sql_filter_builder **filters);
|
||||
|
||||
static schedule_dbo**
|
||||
get_all();
|
||||
|
||||
static int
|
||||
parse_id(const char *id_str, uuid_t result);
|
||||
|
||||
static void
|
||||
unparse_id(const uuid_t id, char *result);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -25,7 +25,8 @@ create table relays
|
|||
controller_id VARCHAR(33) not null
|
||||
references controllers (id),
|
||||
active_schedule_id VARCHAR(33)
|
||||
references schedules
|
||||
references schedules,
|
||||
tag vARCHAR(64)
|
||||
);
|
||||
|
||||
create table schedules
|
||||
|
@ -34,7 +35,9 @@ create table schedules
|
|||
primary key
|
||||
unique,
|
||||
name VARCHAR(128),
|
||||
periods BLOB
|
||||
periods BLOB,
|
||||
tag vARCHAR(64)
|
||||
);
|
||||
|
||||
INSERT INTO schedules (id, name, periods) VALUES ('off', 'off', x'00');
|
||||
INSERT INTO schedules (id, name, periods) VALUES (x'6f666600000000000000000000000000', 'off', x'00');
|
||||
INSERT INTO schedules (id, name, periods) VALUES (x'6f6e0000000000000000000000000000', 'on', x'010000009F05');
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
alter table relays
|
||||
add tag varchar(64);
|
||||
|
||||
alter table controllers
|
||||
add tag varchar(64);
|
||||
|
||||
INSERT INTO schedules (id, name, periods) VALUES ('on', 'on', x'010000009F05');
|
||||
|
25
tavern_tests/test_get_all.tavern.yaml
Normal file
25
tavern_tests/test_get_all.tavern.yaml
Normal file
|
@ -0,0 +1,25 @@
|
|||
test_name: Test basic get all requests
|
||||
|
||||
stages:
|
||||
- name: Get all schedules
|
||||
request:
|
||||
url: "http://localhost:5000/api/v1/schedules/"
|
||||
method: GET
|
||||
response:
|
||||
status_code: 200
|
||||
|
||||
stages:
|
||||
- name: Get all relays
|
||||
request:
|
||||
url: "http://localhost:5000/api/v1/relays/"
|
||||
method: GET
|
||||
response:
|
||||
status_code: 200
|
||||
|
||||
stages:
|
||||
- name: Get all controllers
|
||||
request:
|
||||
url: "http://localhost:5000/api/v1/controllers/"
|
||||
method: GET
|
||||
response:
|
||||
status_code: 200
|
|
@ -1,9 +0,0 @@
|
|||
test_name: Test basic requests
|
||||
|
||||
stages:
|
||||
- name: Make sure we get any response
|
||||
request:
|
||||
url: http://localhost:5000/api/v1/schedules/
|
||||
method: GET
|
||||
response:
|
||||
status_code: 200
|
39
tavern_tests/test_schedules_basic.tavern.yaml
Normal file
39
tavern_tests/test_schedules_basic.tavern.yaml
Normal file
|
@ -0,0 +1,39 @@
|
|||
test_name: Test basic requests
|
||||
|
||||
stages:
|
||||
- name: Make sure we get any response
|
||||
request:
|
||||
url: "http://localhost:5000/api/v1/schedules/"
|
||||
method: GET
|
||||
response:
|
||||
status_code: 200
|
||||
- name: post schedule, expect it to be echoed back
|
||||
request:
|
||||
method: POST
|
||||
url: "http://localhost:5000/api/v1/schedules/"
|
||||
json:
|
||||
name: "hello"
|
||||
periods:
|
||||
- start: '00:10'
|
||||
end: '00:20'
|
||||
- start: '00:30'
|
||||
end: '00:40'
|
||||
- start: '00:50'
|
||||
end: '01:00'
|
||||
response:
|
||||
status_code: 200
|
||||
body:
|
||||
name: "{tavern.request_vars.json.name}"
|
||||
save:
|
||||
body:
|
||||
returned_name: name
|
||||
returned_id: id
|
||||
- name: get schedule, check name and some periods
|
||||
request:
|
||||
method: GET
|
||||
url: "http://localhost:5000/api/v1/schedules/{returned_id}"
|
||||
response:
|
||||
status_code: 200
|
||||
body:
|
||||
name: "{returned_name}"
|
||||
|
Loading…
Reference in a new issue