diff options
author | OpenGnSys Support Team <soporte-og@soleta.eu> | 2024-06-12 11:37:36 +0200 |
---|---|---|
committer | OpenGnSys Support Team <soporte-og@soleta.eu> | 2024-06-12 11:38:08 +0200 |
commit | 9891276246b96ca1bc43383b3e434a7d8f0ed91f (patch) | |
tree | 8033d0ba7cded6fde5f8474ebd09aebc90bd2ca7 /src/dbi.c | |
parent | 51f275a867b4a7007ea6e2aa93f350f08be2680e (diff) |
rest: Add /center/info
Add URI to allow a GET request to obtain info about a center (name, id
and comment of the center as of now).
To use this uri, simply send a GET request with a json containing the id
of the center whose info needs to be consulted:
curl -X GET -H "Authorization: $API_KEY" http://127.0.0.1:8888/center/info -d '{"id":1}'
based on work from Javier Hernandez.
Diffstat (limited to 'src/dbi.c')
-rw-r--r-- | src/dbi.c | 33 |
1 files changed, 33 insertions, 0 deletions
@@ -129,6 +129,39 @@ int og_dbi_get_computer_info(struct og_dbi *dbi, struct og_computer *computer, return 0; } +int og_dbi_get_center_info(struct og_dbi *dbi, struct og_center *center) +{ + const char *msglog; + dbi_result result; + + result = dbi_conn_queryf(dbi->conn, + "SELECT nombrecentro, idcentro, comentarios " + "FROM centros WHERE idcentro=%d", + center->id); + if (!result) { + dbi_conn_error(dbi->conn, &msglog); + syslog(LOG_ERR, "failed to query database (%s:%d) %s\n", + __func__, __LINE__, msglog); + return -1; + } + + if (!dbi_result_next_row(result)) { + syslog(LOG_ERR, "center does not exist in database (%s:%d)\n", + __func__, __LINE__); + dbi_result_free(result); + return -1; + } + + snprintf(center->name, sizeof(center->name), "%s", + dbi_result_get_string(result, "nombrecentro")); + snprintf(center->comment, sizeof(center->comment), "%s", + dbi_result_get_string(result, "comentarios")); + + dbi_result_free(result); + + return 0; +} + int og_dbi_get_room_info(struct og_dbi *dbi, struct og_room *room, uint32_t room_id) { |