add: tests
This commit is contained in:
parent
760cec9a20
commit
865caa627e
15 changed files with 558 additions and 386 deletions
|
|
@ -31,8 +31,31 @@ api_v1_schedules_POST(struct mg_connection *nc, struct http_message *hm, endpoin
|
|||
endpoint_response_text(response, 400, content, STRLEN(content));
|
||||
return;
|
||||
}
|
||||
cJSON *json_period;
|
||||
cJSON *json_periods = cJSON_GetObjectItemCaseSensitive(json, "periods");
|
||||
if(!cJSON_IsArray(json_periods))
|
||||
{
|
||||
LOG_DEBUG("no periods for schedule provided\n");
|
||||
cJSON_Delete(json);
|
||||
|
||||
static const char content[] = "no periods for schedule provided";
|
||||
endpoint_response_text(response, 400, content, STRLEN(content));
|
||||
return;
|
||||
}
|
||||
|
||||
cJSON *json_tag;
|
||||
cJSON *json_tags = cJSON_GetObjectItemCaseSensitive(json, "tags");
|
||||
cJSON_ArrayForEach(json_tag, json_tags)
|
||||
{
|
||||
if(!cJSON_IsString(json_tag) || (json_tag->valuestring == NULL))
|
||||
{
|
||||
LOG_DEBUG("invalid tag in tags\n");
|
||||
cJSON_Delete(json);
|
||||
|
||||
static const char content[] = "invalid tag in tags";
|
||||
endpoint_response_text(response, 400, content, STRLEN(content));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
schedule_t *new_schedule = malloc(sizeof(schedule_t));
|
||||
|
||||
|
|
@ -47,6 +70,7 @@ api_v1_schedules_POST(struct mg_connection *nc, struct http_message *hm, endpoin
|
|||
|
||||
int periods_valid = 0;
|
||||
|
||||
cJSON *json_period;
|
||||
cJSON_ArrayForEach(json_period, json_periods)
|
||||
{
|
||||
cJSON *json_period_start = cJSON_GetObjectItemCaseSensitive(json_period, "start");
|
||||
|
|
@ -106,23 +130,18 @@ api_v1_schedules_POST(struct mg_connection *nc, struct http_message *hm, endpoin
|
|||
schedule_save(new_schedule);
|
||||
|
||||
junction_tag_remove_for_schedule(new_schedule->id);
|
||||
cJSON *json_tag;
|
||||
cJSON *json_tags = cJSON_GetObjectItemCaseSensitive(json, "tags");
|
||||
|
||||
json_tags = cJSON_GetObjectItemCaseSensitive(json, "tags");
|
||||
cJSON_ArrayForEach(json_tag, json_tags)
|
||||
{
|
||||
if(!cJSON_IsString(json_tag) || (json_tag->valuestring == NULL))
|
||||
{
|
||||
LOG_DEBUG("invalid tag in tags\n");
|
||||
continue;
|
||||
}
|
||||
const char *tag = json_tag->valuestring;
|
||||
int tag_id = tag_get_id(tag);
|
||||
if(tag_id == 0)
|
||||
{
|
||||
tag_save(tag_id, tag);
|
||||
tag_id = tag_get_id(tag);
|
||||
}
|
||||
junction_tag_insert(tag_id, 0, new_schedule->id);
|
||||
const char *tag = json_tag->valuestring;
|
||||
int tag_id = tag_get_id(tag);
|
||||
if(tag_id == 0)
|
||||
{
|
||||
tag_save(tag_id, tag);
|
||||
tag_id = tag_get_id(tag);
|
||||
}
|
||||
junction_tag_insert(tag_id, 0, new_schedule->id);
|
||||
}
|
||||
|
||||
cJSON_Delete(json);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue