feat(restful): add api for subscribing multiple groups

This commit is contained in:
eeff
2023-08-07 10:35:09 +08:00
parent d41a83bcfe
commit f022f1c388
3 changed files with 51 additions and 0 deletions
+41
View File
@@ -265,6 +265,47 @@ void handle_grp_unsubscribe(nng_aio *aio)
})
}
static inline int send_subscribe_groups(nng_aio * aio,
neu_json_subscribe_groups_req_t *req)
{
neu_plugin_t *plugin = neu_rest_get_plugin();
neu_reqresp_head_t header = {
.ctx = aio,
.type = NEU_REQ_SUBSCRIBE_GROUPS,
};
neu_req_subscribe_groups_t cmd = {
.app = req->app,
.n_group = req->n_group,
.groups = (neu_req_subscribe_group_info_t *) req->groups,
};
if (0 != neu_plugin_op(plugin, header, &cmd)) {
return NEU_ERR_IS_BUSY;
}
// ownership moved
req->app = NULL;
req->n_group = 0;
req->groups = NULL;
return 0;
}
void handle_grp_subscribes(nng_aio *aio)
{
NEU_PROCESS_HTTP_REQUEST_VALIDATE_JWT(
aio, neu_json_subscribe_groups_req_t,
neu_json_decode_subscribe_groups_req, {
int ret = send_subscribe_groups(aio, req);
if (0 != ret) {
NEU_JSON_RESPONSE_ERROR(
ret, { neu_http_response(aio, ret, result_error); });
}
})
}
void handle_grp_get_subscribe(nng_aio *aio)
{
int ret = 0;
+1
View File
@@ -34,6 +34,7 @@ void handle_get_driver_group_resp(nng_aio * aio,
void handle_grp_subscribe(nng_aio *aio);
void handle_grp_update_subscribe(nng_aio *aio);
void handle_grp_unsubscribe(nng_aio *aio);
void handle_grp_subscribes(nng_aio *aio);
void handle_grp_get_subscribe(nng_aio *aio);
void handle_grp_get_subscribe_resp(nng_aio * aio,
neu_resp_get_subscribe_group_t *groups);
+9
View File
@@ -80,6 +80,9 @@ static struct neu_http_handler cors_handler[] = {
{
.url = "/api/v2/subscribe",
},
{
.url = "/api/v2/subscribes",
},
{
.url = "/api/v2/schema",
},
@@ -304,6 +307,12 @@ static struct neu_http_handler rest_handlers[] = {
.url = "/api/v2/subscribe",
.value.handler = handle_grp_get_subscribe,
},
{
.method = NEU_HTTP_METHOD_POST,
.type = NEU_HTTP_HANDLER_FUNCTION,
.url = "/api/v2/subscribes",
.value.handler = handle_grp_subscribes,
},
{
.method = NEU_HTTP_METHOD_GET,
.type = NEU_HTTP_HANDLER_FUNCTION,