add: tests
add: schedule endpoints
This commit is contained in:
parent
6d828fcffc
commit
b5a8523ae0
14 changed files with 468 additions and 42 deletions
|
|
@ -1,4 +1,5 @@
|
|||
#include <cJSON.h>
|
||||
#include <constants.h>
|
||||
#include <endpoints/api_v1_schedules.h>
|
||||
#include <logger.h>
|
||||
#include <models/junction_tag.h>
|
||||
|
|
@ -24,9 +25,9 @@ api_v1_schedules_POST(struct mg_connection *c, endpoint_args_t *args, struct htt
|
|||
cJSON *json_name = cJSON_GetObjectItemCaseSensitive(json, "name");
|
||||
if(!cJSON_IsString(json_name) || (json_name->valuestring == NULL))
|
||||
{
|
||||
char *error_msg = "ERROR: no name for schedule provided";
|
||||
mg_send_head(c, 400, strlen(error_msg), "Content-Type: text/plain");
|
||||
mg_printf(c, "%s", error_msg);
|
||||
LOG_DEBUG("no name for schedule provided\n");
|
||||
mg_send_head(c, 400, 2, "Content-Type: application/json\r\n" STANDARD_HEADERS);
|
||||
mg_printf(c, "{}");
|
||||
|
||||
cJSON_Delete(json);
|
||||
return;
|
||||
|
|
@ -112,12 +113,12 @@ api_v1_schedules_POST(struct mg_connection *c, endpoint_args_t *args, struct htt
|
|||
if (json_str == NULL)
|
||||
{
|
||||
LOG_ERROR("failed to print schedule json\n");
|
||||
mg_send_head(c, 201, 2, "Content-Type: application/json");
|
||||
mg_send_head(c, 201, 2, "Content-Type: application/json\r\n" STANDARD_HEADERS);
|
||||
mg_printf(c, "{}");
|
||||
}
|
||||
else
|
||||
{
|
||||
mg_send_head(c, 201, strlen(json_str), "Content-Type: application/json");
|
||||
mg_send_head(c, 201, strlen(json_str), "Content-Type: application/json\r\n" STANDARD_HEADERS);
|
||||
mg_printf(c, "%s", json_str);
|
||||
free(json_str);
|
||||
}
|
||||
|
|
@ -145,12 +146,12 @@ api_v1_schedules_GET(struct mg_connection *c, endpoint_args_t *args, struct http
|
|||
if (json_str == NULL)
|
||||
{
|
||||
LOG_ERROR("failed to print schedules json\n");
|
||||
mg_send_head(c, 500, 2, "Content-Type: application/json");
|
||||
mg_send_head(c, 500, 2, "Content-Type: application/json\r\n" STANDARD_HEADERS);
|
||||
mg_printf(c, "[]");
|
||||
}
|
||||
else
|
||||
{
|
||||
mg_send_head(c, 200, strlen(json_str), "Content-Type: application/json");
|
||||
mg_send_head(c, 200, strlen(json_str), "Content-Type: application/json\r\n" STANDARD_HEADERS);
|
||||
mg_printf(c, "%s", json_str);
|
||||
free(json_str);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue