Add text responses as json with msg key

This commit is contained in:
Tobias Reisinger 2020-11-13 23:20:07 +01:00
parent f97b149376
commit 1d6e8ff037
18 changed files with 114 additions and 83 deletions
src/endpoints

View file

@ -81,7 +81,7 @@ api_v1_macros_STR_PUT(struct mg_connection *nc, struct http_message *hm, endpoin
cJSON_Delete(json);
macro_free(macro);
M_RESPONSE_TEXT_STATIC(LOGGER_ERR, response, 500, "macro could not be saved");
M_RESPONSE_500_FAILED_TO_SAVE_TO_DATABASE(response);
return;
}
}
@ -101,7 +101,7 @@ api_v1_macros_STR_PUT(struct mg_connection *nc, struct http_message *hm, endpoin
cJSON_Delete(json);
macro_free(macro);
M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "at least one action is missing a weekday");
M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "at least one action is missing a weekday");
return;
}
@ -112,7 +112,7 @@ api_v1_macros_STR_PUT(struct mg_connection *nc, struct http_message *hm, endpoin
cJSON_Delete(json);
macro_free(macro);
M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "at least one action is missing a schedule");
M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "at least one action is missing a schedule");
return;
}
cJSON *json_action_schedule_uid = cJSON_GetObjectItemCaseSensitive(json_action_schedule, "id");
@ -122,7 +122,7 @@ api_v1_macros_STR_PUT(struct mg_connection *nc, struct http_message *hm, endpoin
cJSON_Delete(json);
macro_free(macro);
M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "at least one action is missing a schedule id");
M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "at least one action is missing a schedule id");
return;
}
uuid_t action_schedule_uid;
@ -132,7 +132,7 @@ api_v1_macros_STR_PUT(struct mg_connection *nc, struct http_message *hm, endpoin
cJSON_Delete(json);
macro_free(macro);
M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "at least one action has a bad schedule id");
M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "at least one action has a bad schedule id");
return;
}
@ -143,7 +143,7 @@ api_v1_macros_STR_PUT(struct mg_connection *nc, struct http_message *hm, endpoin
cJSON_Delete(json);
macro_free(macro);
M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "at least one action schedule was not found");
M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "at least one action schedule was not found");
return;
}
@ -158,7 +158,7 @@ api_v1_macros_STR_PUT(struct mg_connection *nc, struct http_message *hm, endpoin
cJSON_Delete(json);
macro_free(macro);
M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "at least one action is missing a relay");
M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "at least one action is missing a relay");
return;
}
cJSON *json_action_relay_number = cJSON_GetObjectItemCaseSensitive(json_action_relay, "number");
@ -168,7 +168,7 @@ api_v1_macros_STR_PUT(struct mg_connection *nc, struct http_message *hm, endpoin
cJSON_Delete(json);
macro_free(macro);
M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "at least one action is missing a relay number");
M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "at least one action is missing a relay number");
return;
}
cJSON *json_action_relay_controller_uid = cJSON_GetObjectItemCaseSensitive(json_action_relay, "controller_id");
@ -178,7 +178,7 @@ api_v1_macros_STR_PUT(struct mg_connection *nc, struct http_message *hm, endpoin
cJSON_Delete(json);
macro_free(macro);
M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "at least one action is missing a relay controller id");
M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "at least one action is missing a relay controller id");
return;
}
uuid_t action_controller_uid;
@ -188,7 +188,7 @@ api_v1_macros_STR_PUT(struct mg_connection *nc, struct http_message *hm, endpoin
cJSON_Delete(json);
macro_free(macro);
M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "at least one action has a bad relay controller id");
M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "at least one action has a bad relay controller id");
return;
}
@ -199,7 +199,7 @@ api_v1_macros_STR_PUT(struct mg_connection *nc, struct http_message *hm, endpoin
cJSON_Delete(json);
macro_free(macro);
M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "at least one action relay controller was not found");
M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "at least one action relay controller was not found");
return;
}
@ -215,7 +215,7 @@ api_v1_macros_STR_PUT(struct mg_connection *nc, struct http_message *hm, endpoin
cJSON_Delete(json);
macro_free(macro);
M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 400, "action relay was not found");
M_RESPONSE_MSG(LOGGER_DEBUG, response, 400, "action relay was not found");
return;
}
@ -264,17 +264,17 @@ api_v1_macros_STR_DELETE(struct mg_connection *nc, struct http_message *hm, endp
if(!macro)
{
M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 404, "no macro with id found");
M_RESPONSE_404_NO_MACRO_FOUND_FOR_ID(response);
return;
}
if(macro_remove(macro))
{
M_RESPONSE_TEXT_STATIC(LOGGER_ERR, response, 500, "failed to remove macro from database");
M_RESPONSE_500_FAILED_TO_DELETE_FROM_DATABASE(response);
}
else
{
M_RESPONSE_TEXT_STATIC(LOGGER_DEBUG, response, 200, "deleted macro");
M_RESPONSE_MSG(LOGGER_DEBUG, response, 200, "deleted macro");
}
macro_free(macro);
return;