summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlejandro Sirgo Rica <asirgo@soleta.eu>2024-06-12 12:44:11 +0200
committerAlejandro Sirgo Rica <asirgo@soleta.eu>2024-06-12 12:44:11 +0200
commit5103a2eacd47cd8cf2324cd2fc1c48311a4112a4 (patch)
tree06fba0dfc364b2209d0930779f0d097ba4109be1 /src
parentcdc339659f867f302a60f18f07284c04bc034a21 (diff)
rest: allow the same center name in center update
Exclude centerid of the center we update from the search of centers with the same name. Report when other center have the same name as the one in the payload of the update request.
Diffstat (limited to 'src')
-rw-r--r--src/rest.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/rest.c b/src/rest.c
index 7ffebbf..3d881a8 100644
--- a/src/rest.c
+++ b/src/rest.c
@@ -1812,11 +1812,11 @@ static int og_cmd_post_center_update(json_t *element,
struct og_msg_params *params)
{
const char *key, *msglog;
+ uint32_t center_id;
struct og_dbi *dbi;
dbi_result result;
json_t *value;
int err = 0;
- unsigned int center_id;
json_object_foreach(element, key, value) {
if (!strcmp(key, "name")) {
@@ -1865,8 +1865,9 @@ static int og_cmd_post_center_update(json_t *element,
dbi_result_free(result);
result = dbi_conn_queryf(dbi->conn,
- "SELECT nombrecentro FROM centros WHERE nombrecentro='%s'",
- params->name);
+ "SELECT idcentro FROM centros "
+ "WHERE nombrecentro='%s' and idcentro<>'%u'",
+ params->name, center_id);
if (!result) {
dbi_conn_error(dbi->conn, &msglog);
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
@@ -1874,9 +1875,10 @@ static int og_cmd_post_center_update(json_t *element,
og_dbi_close(dbi);
return -1;
}
- if (dbi_result_get_numrows(result) != 0) {
- syslog(LOG_ERR, "a center with that name already exists: %s\n",
- params->name);
+ if (dbi_result_next_row(result)) {
+ center_id = dbi_result_get_uint(result, "idcentro");
+ syslog(LOG_ERR, "the center with id %u already has the name: %s\n",
+ center_id, params->name);
dbi_result_free(result);
og_dbi_close(dbi);
return -1;