From fcc01cf22b6f390c96ce46b61bacb0eb034b49ef Mon Sep 17 00:00:00 2001 From: eeff <33566201+eeff@users.noreply.github.com> Date: Mon, 22 May 2023 14:50:30 +0800 Subject: [PATCH] feat(restful): add node update api --- plugins/restful/adapter_handle.c | 24 ++++++++++++++++++++++++ plugins/restful/adapter_handle.h | 1 + plugins/restful/handle.c | 6 ++++++ 3 files changed, 31 insertions(+) diff --git a/plugins/restful/adapter_handle.c b/plugins/restful/adapter_handle.c index 6a2b0bee..e7cdeb0b 100644 --- a/plugins/restful/adapter_handle.c +++ b/plugins/restful/adapter_handle.c @@ -62,6 +62,30 @@ void handle_add_adapter(nng_aio *aio) }) } +void handle_update_adapter(nng_aio *aio) +{ + neu_plugin_t *plugin = neu_rest_get_plugin(); + + NEU_PROCESS_HTTP_REQUEST_VALIDATE_JWT( + aio, neu_json_update_node_req_t, neu_json_decode_update_node_req, { + int ret = 0; + neu_reqresp_head_t header = { 0 }; + neu_req_update_node_t cmd = { 0 }; + + header.ctx = aio; + header.type = NEU_REQ_UPDATE_NODE; + strcpy(cmd.node, req->name); + strcpy(cmd.new_name, req->new_name); + + ret = neu_plugin_op(plugin, header, &cmd); + if (ret != 0) { + NEU_JSON_RESPONSE_ERROR(NEU_ERR_IS_BUSY, { + neu_http_response(aio, NEU_ERR_IS_BUSY, result_error); + }); + } + }) +} + void handle_del_adapter(nng_aio *aio) { neu_plugin_t *plugin = neu_rest_get_plugin(); diff --git a/plugins/restful/adapter_handle.h b/plugins/restful/adapter_handle.h index 693263d5..924d3403 100644 --- a/plugins/restful/adapter_handle.h +++ b/plugins/restful/adapter_handle.h @@ -24,6 +24,7 @@ #include "adapter.h" void handle_add_adapter(nng_aio *aio); +void handle_update_adapter(nng_aio *aio); void handle_del_adapter(nng_aio *aio); void handle_get_adapter(nng_aio *aio); void handle_get_adapter_resp(nng_aio *aio, neu_resp_get_node_t *nodes); diff --git a/plugins/restful/handle.c b/plugins/restful/handle.c index 913aacb4..21f9cb03 100644 --- a/plugins/restful/handle.c +++ b/plugins/restful/handle.c @@ -216,6 +216,12 @@ static struct neu_http_handler rest_handlers[] = { .url = "/api/v2/node", .value.handler = handle_add_adapter, }, + { + .method = NEU_HTTP_METHOD_PUT, + .type = NEU_HTTP_HANDLER_FUNCTION, + .url = "/api/v2/node", + .value.handler = handle_update_adapter, + }, { .method = NEU_HTTP_METHOD_DELETE, .type = NEU_HTTP_HANDLER_FUNCTION,