From aa4e94cc6daec01066b841118c3a7b975e598403 Mon Sep 17 00:00:00 2001 From: eeff <33566201+eeff@users.noreply.github.com> Date: Thu, 4 May 2023 11:07:28 +0800 Subject: [PATCH] feat(restful): add template group del api --- plugins/restful/handle.c | 6 ++++++ plugins/restful/template_handle.c | 23 +++++++++++++++++++++++ plugins/restful/template_handle.h | 1 + 3 files changed, 30 insertions(+) diff --git a/plugins/restful/handle.c b/plugins/restful/handle.c index 5509fa08..c4c6fe8b 100644 --- a/plugins/restful/handle.c +++ b/plugins/restful/handle.c @@ -408,6 +408,12 @@ static struct neu_http_handler rest_handlers[] = { .url = "/api/v2/template/group", .value.handler = handle_update_template_group, }, + { + .method = NEU_HTTP_METHOD_DELETE, + .type = NEU_HTTP_HANDLER_FUNCTION, + .url = "/api/v2/template/group", + .value.handler = handle_del_template_group, + }, }; void neu_rest_handler(const struct neu_http_handler **handlers, uint32_t *size) diff --git a/plugins/restful/template_handle.c b/plugins/restful/template_handle.c index 5c07d0e5..6b25aedb 100644 --- a/plugins/restful/template_handle.c +++ b/plugins/restful/template_handle.c @@ -380,6 +380,29 @@ void handle_update_template_group(nng_aio *aio) process_mod_template_group(aio, NEU_REQ_UPDATE_TEMPLATE_GROUP); } +void handle_del_template_group(nng_aio *aio) +{ + neu_plugin_t *plugin = neu_rest_get_plugin(); + + NEU_PROCESS_HTTP_REQUEST_VALIDATE_JWT( + aio, neu_json_template_del_group_req_t, + neu_json_decode_template_del_group_req, { + neu_reqresp_head_t header = { 0 }; + header.ctx = aio; + header.type = NEU_REQ_DEL_TEMPLATE_GROUP; + + neu_req_add_template_group_t cmd = { 0 }; + strcpy(cmd.tmpl, req->tmpl); + strcpy(cmd.group, req->group); + + if (0 != neu_plugin_op(plugin, header, &cmd)) { + int ret = NEU_ERR_IS_BUSY; + NEU_JSON_RESPONSE_ERROR( + ret, { neu_http_response(aio, ret, result_error); }); + } + }) +} + static int send_template_mod_tags_req(nng_aio *aio, neu_reqresp_type_e type, neu_json_template_mod_tags_req_t *req) { diff --git a/plugins/restful/template_handle.h b/plugins/restful/template_handle.h index 2acd1b4e..6f0b51d1 100644 --- a/plugins/restful/template_handle.h +++ b/plugins/restful/template_handle.h @@ -32,6 +32,7 @@ void handle_get_templates_resp(nng_aio *aio, neu_resp_get_templates_t *resp); void handle_add_template_group(nng_aio *aio); void handle_update_template_group(nng_aio *aio); +void handle_del_template_group(nng_aio *aio); void handle_add_template_tags(nng_aio *aio); void handle_update_template_tags(nng_aio *aio);