#include #include #include #include "api_v1_devices.h" using namespace api::v1; void devices::get_relays_all(const HttpRequestPtr &req, std::function &&callback, const std::string& device_id) { relay_dbo **all_device_relays = relay_dbo::get_by_simple("device_id", (void *) device_id.c_str(), (intptr_t) sqlite3_bind_text); Json::Value all_relays_json(Json::arrayValue); for(int i = 0; all_device_relays[i] != nullptr; i++) { all_relays_json.append(all_device_relays[i]->to_json()); } auto resp = HttpResponse::newHttpJsonResponse(all_relays_json); callback(resp); relay_dbo::free_list(all_device_relays); } void devices::get_relays_one_by_id_and_num(const HttpRequestPtr &req, std::function &&callback, const std::string& device_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, "AND" }; helpers::sql_filter_builder filter2 { "device_id", (void*)device_id.c_str(), (intptr_t)sqlite3_bind_text, ";" }; filters[0] = &filter; filters[1] = &filter2; auto relays = relay_dbo::get_by(filters); 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); } void devices::put_relays_one_by_id_and_num(const HttpRequestPtr &req, std::function &&callback, const std::string& device_id, int relay_num) { }