mirror of https://git.48k.eu/ogserver
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.master
parent
cdc339659f
commit
5103a2eacd
14
src/rest.c
14
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;
|
||||
|
|
Loading…
Reference in New Issue