fix: name cutting off
add: schedules post list
This commit is contained in:
parent
a234a79828
commit
b9154cdc3b
2 changed files with 39 additions and 1 deletions
|
@ -119,7 +119,6 @@ schedules::post_new(const HttpRequestPtr &req, std::function<void(const HttpResp
|
||||||
strncpy(new_schedule.name, body["name"].asCString(), 127);
|
strncpy(new_schedule.name, body["name"].asCString(), 127);
|
||||||
new_schedule.name[127] = '\0';
|
new_schedule.name[127] = '\0';
|
||||||
uuid_generate(new_schedule.uid);
|
uuid_generate(new_schedule.uid);
|
||||||
new_schedule.uid[32] = '\0';
|
|
||||||
new_schedule.periods = helpers::parse_periods(body["periods"]);
|
new_schedule.periods = helpers::parse_periods(body["periods"]);
|
||||||
|
|
||||||
if(!new_schedule.insert())
|
if(!new_schedule.insert())
|
||||||
|
@ -135,6 +134,43 @@ schedules::post_new(const HttpRequestPtr &req, std::function<void(const HttpResp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
schedules::post_list(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback)
|
||||||
|
{
|
||||||
|
Json::Value body = *req->jsonObject();
|
||||||
|
|
||||||
|
Json::Value schedules_json(Json::arrayValue);
|
||||||
|
|
||||||
|
for(int i = 0; i < body.size(); ++i)
|
||||||
|
{
|
||||||
|
bool set_name = body[i]["name"].type() == Json::ValueType::stringValue;
|
||||||
|
bool set_tags = body[i]["tags"].type() == Json::ValueType::arrayValue;
|
||||||
|
//bool set_periods = body[i]["periods"].type() == Json::ValueType::arrayValue;
|
||||||
|
|
||||||
|
if(!set_name || !set_name)
|
||||||
|
{
|
||||||
|
auto resp = HttpResponse::newHttpResponse();
|
||||||
|
resp->setStatusCode(k400BadRequest);
|
||||||
|
callback(resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
schedule_dbo new_schedule{};
|
||||||
|
|
||||||
|
strncpy(new_schedule.name, body[i]["name"].asCString(), 127);
|
||||||
|
new_schedule.name[127] = '\0';
|
||||||
|
uuid_generate(new_schedule.uid);
|
||||||
|
new_schedule.periods = helpers::parse_periods(body[i]["periods"]);
|
||||||
|
|
||||||
|
if(new_schedule.insert())
|
||||||
|
{
|
||||||
|
schedules_json.append(new_schedule.to_json());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto resp = HttpResponse::newHttpJsonResponse(schedules_json);
|
||||||
|
callback(resp);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
schedules::put_one_by_id(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback,
|
schedules::put_one_by_id(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback,
|
||||||
const std::string &schedule_id_str)
|
const std::string &schedule_id_str)
|
||||||
|
|
|
@ -8,6 +8,7 @@ namespace api::v1
|
||||||
public:
|
public:
|
||||||
METHOD_LIST_BEGIN
|
METHOD_LIST_BEGIN
|
||||||
METHOD_ADD(schedules::post_new, "/", Post, Options, "filters::json_required", "filters::schedules::valid_json");
|
METHOD_ADD(schedules::post_new, "/", Post, Options, "filters::json_required", "filters::schedules::valid_json");
|
||||||
|
METHOD_ADD(schedules::post_list, "/list", Post, Options, "filters::json_required");
|
||||||
METHOD_ADD(schedules::get_all, "/", Get, Options);
|
METHOD_ADD(schedules::get_all, "/", Get, Options);
|
||||||
METHOD_ADD(schedules::get_one_by_id, "/{1}", 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::delete_one_by_id, "/{1}", Delete, Options);
|
||||||
|
@ -18,6 +19,7 @@ namespace api::v1
|
||||||
METHOD_LIST_END
|
METHOD_LIST_END
|
||||||
|
|
||||||
static void post_new(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback);
|
static void post_new(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback);
|
||||||
|
static void post_list(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_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& schedule_id);
|
static void get_one_by_id(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback, const std::string& schedule_id);
|
||||||
static void delete_one_by_id(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback, const std::string& schedule_id);
|
static void delete_one_by_id(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback, const std::string& schedule_id);
|
||||||
|
|
Loading…
Reference in a new issue