mirror of https://git.48k.eu/ogserver
#915 Add POST /repository/delete
This method deletes a repository from the database.
Request:
POST /repository/delete
{
"id": "10"
}
Response:
200 OK
master
parent
86ccc3c2e8
commit
5cf2de704c
62
src/rest.c
62
src/rest.c
|
|
@ -5045,6 +5045,54 @@ static int og_cmd_post_repository_add(json_t *element,
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int og_cmd_post_repository_delete(json_t *element,
|
||||||
|
struct og_msg_params *params)
|
||||||
|
{
|
||||||
|
const char *key, *msglog;
|
||||||
|
struct og_dbi *dbi;
|
||||||
|
dbi_result result;
|
||||||
|
json_t *value;
|
||||||
|
int err = 0;
|
||||||
|
|
||||||
|
json_object_foreach(element, key, value) {
|
||||||
|
if (!strcmp(key, "id")) {
|
||||||
|
err = og_json_parse_string(value, ¶ms->id);
|
||||||
|
params->flags |= OG_REST_PARAM_ID;
|
||||||
|
}
|
||||||
|
if (err < 0)
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!og_msg_params_validate(params, OG_REST_PARAM_ID))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
dbi = og_dbi_open(&ogconfig.db);
|
||||||
|
if (!dbi) {
|
||||||
|
syslog(LOG_ERR, "cannot open conection database (%s:%d)\n",
|
||||||
|
__func__, __LINE__);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = dbi_conn_queryf(dbi->conn,
|
||||||
|
"DELETE FROM repositorios "
|
||||||
|
"WHERE idrepositorio=%s",
|
||||||
|
params->id);
|
||||||
|
|
||||||
|
if (!result) {
|
||||||
|
dbi_conn_error(dbi->conn, &msglog);
|
||||||
|
syslog(LOG_ERR, "failed to delete repository from database "
|
||||||
|
"(%s:%d) %s\n",
|
||||||
|
__func__, __LINE__, msglog);
|
||||||
|
og_dbi_close(dbi);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
dbi_result_free(result);
|
||||||
|
og_dbi_close(dbi);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int og_cmd_post_room_add(json_t *element,
|
static int og_cmd_post_room_add(json_t *element,
|
||||||
struct og_msg_params *params)
|
struct og_msg_params *params)
|
||||||
{
|
{
|
||||||
|
|
@ -6002,6 +6050,20 @@ int og_client_state_process_payload_rest(struct og_client *cli)
|
||||||
goto err_process_rest_payload;
|
goto err_process_rest_payload;
|
||||||
}
|
}
|
||||||
err = og_cmd_post_repository_add(root, ¶ms);
|
err = og_cmd_post_repository_add(root, ¶ms);
|
||||||
|
} else if (!strncmp(cmd, "repository/delete",
|
||||||
|
strlen("repository/delete"))) {
|
||||||
|
if (method != OG_METHOD_POST) {
|
||||||
|
err = og_client_method_not_found(cli);
|
||||||
|
goto err_process_rest_payload;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!root) {
|
||||||
|
syslog(LOG_ERR,
|
||||||
|
"command repository delete with no payload\n");
|
||||||
|
err = og_client_bad_request(cli);
|
||||||
|
goto err_process_rest_payload;
|
||||||
|
}
|
||||||
|
err = og_cmd_post_repository_delete(root, ¶ms);
|
||||||
} else if (!strncmp(cmd, "images", strlen("images"))) {
|
} else if (!strncmp(cmd, "images", strlen("images"))) {
|
||||||
if (method != OG_METHOD_GET) {
|
if (method != OG_METHOD_GET) {
|
||||||
err = og_client_method_not_found(cli);
|
err = og_client_method_not_found(cli);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue