feat(restful): template add tags api

This commit is contained in:
eeff
2023-04-14 12:13:12 +08:00
parent 0d8d76ddb6
commit fec281e89c
4 changed files with 65 additions and 0 deletions
+9
View File
@@ -112,6 +112,9 @@ static struct neu_http_handler cors_handler[] = {
{
.url = "/api/v2/template",
},
{
.url = "/api/v2/template/tag",
},
};
static struct neu_http_handler rest_handlers[] = {
@@ -357,6 +360,12 @@ static struct neu_http_handler rest_handlers[] = {
.url = "/api/v2/template",
.value.handler = handle_get_template,
},
{
.method = NEU_HTTP_METHOD_POST,
.type = NEU_HTTP_HANDLER_FUNCTION,
.url = "/api/v2/template/tag",
.value.handler = handle_add_template_tags,
},
};
void neu_rest_handler(const struct neu_http_handler **handlers, uint32_t *size)
+1
View File
@@ -197,6 +197,7 @@ static int dashb_plugin_request(neu_plugin_t * plugin,
(neu_resp_get_driver_group_t *) data);
break;
case NEU_RESP_ADD_TAG:
case NEU_RESP_ADD_TEMPLATE_TAG:
handle_add_tags_resp(header->ctx, (neu_resp_add_tag_t *) data);
break;
case NEU_RESP_UPDATE_TAG:
+53
View File
@@ -157,6 +157,7 @@ void handle_add_template(nng_aio *aio)
}
if (0 != ret) {
neu_reqresp_template_fini(&cmd);
NEU_JSON_RESPONSE_ERROR(
ret, { neu_http_response(aio, ret, result_error); });
}
@@ -319,3 +320,55 @@ void handle_get_templates_resp(nng_aio *aio, neu_resp_get_templates_t *resp)
neu_resp_get_templates_fini(resp);
return;
}
static int send_template_tags_req(nng_aio *aio, neu_reqresp_type_e type,
neu_json_template_mod_tags_req_t *req)
{
neu_plugin_t *plugin = neu_rest_get_plugin();
int ret = 0;
int i = 0;
neu_reqresp_head_t header = {
.ctx = aio,
.type = type,
};
neu_req_add_template_tag_t cmd = { 0 };
strcpy(cmd.tmpl, req->tmpl);
strcpy(cmd.group, req->group);
cmd.tags = calloc(req->n_tag, sizeof(neu_datatag_t));
if (NULL == cmd.tags) {
return NEU_ERR_EINTERNAL;
}
for (i = 0; i < req->n_tag; i++) {
cmd.n_tag += 1;
if (0 != (ret = set_tag_by_json(&cmd.tags[i], &req->tags[i]))) {
neu_req_add_template_tag_fini(&cmd);
return ret;
}
}
if (0 != neu_plugin_op(plugin, header, &cmd)) {
neu_req_add_template_tag_fini(&cmd);
return NEU_ERR_IS_BUSY;
}
return ret;
}
void handle_add_template_tags(nng_aio *aio)
{
NEU_PROCESS_HTTP_REQUEST_VALIDATE_JWT(
aio, neu_json_template_mod_tags_req_t,
neu_json_decode_template_mod_tags_req, {
int ret =
send_template_tags_req(aio, NEU_REQ_ADD_TEMPLATE_TAG, req);
if (0 != ret) {
NEU_JSON_RESPONSE_ERROR(
ret, { neu_http_response(aio, ret, result_error); });
}
})
}
+2
View File
@@ -30,4 +30,6 @@ void handle_get_template(nng_aio *aio);
void handle_get_template_resp(nng_aio *aio, neu_resp_get_template_t *resp);
void handle_get_templates_resp(nng_aio *aio, neu_resp_get_templates_t *resp);
void handle_add_template_tags(nng_aio *aio);
#endif