core-legacy/endpoints/api_v1_relays.c

32 lines
738 B
C
Raw Normal View History

#include <cJSON.h>
2020-05-20 23:33:18 +00:00
#include <macros.h>
#include <constants.h>
#include <endpoints/api_v1_relays.h>
#include <logger.h>
#include <models/junction_tag.h>
#include <models/relay.h>
#include <models/tag.h>
void
2020-05-31 00:07:25 +00:00
api_v1_relays_GET(struct mg_connection *nc, struct http_message *hm, endpoint_args_t *args, endpoint_response_t *response)
{
(void)args;
(void)hm;
2020-05-31 00:07:25 +00:00
(void)nc;
relay_t** all_relays = relay_get_all();
cJSON *json = cJSON_CreateArray();
for(int i = 0; all_relays[i] != NULL; ++i)
{
cJSON *json_relay = relay_to_json(all_relays[i]);
cJSON_AddItemToArray(json, json_relay);
}
2020-05-30 22:23:57 +00:00
endpoint_response_json(response, 200, json);
cJSON_Delete(json);
relay_free_list(all_relays);
}