fix(api): sub api return meta
This commit is contained in:
parent
964a77510d
commit
f36791bab9
|
@ -30,6 +30,10 @@
|
||||||
|
|
||||||
-export([do_query/5]).
|
-export([do_query/5]).
|
||||||
|
|
||||||
|
-export([ page/1
|
||||||
|
, limit/1
|
||||||
|
]).
|
||||||
|
|
||||||
paginate(Tables, Params, RowFun) ->
|
paginate(Tables, Params, RowFun) ->
|
||||||
Qh = query_handle(Tables),
|
Qh = query_handle(Tables),
|
||||||
Count = count(Tables),
|
Count = count(Tables),
|
||||||
|
|
|
@ -64,8 +64,10 @@ list(Bindings, Params) when map_size(Bindings) == 0 ->
|
||||||
case proplists:get_value(<<"topic">>, Params) of
|
case proplists:get_value(<<"topic">>, Params) of
|
||||||
undefined ->
|
undefined ->
|
||||||
minirest:return({ok, emqx_mgmt_api:cluster_query(Params, ?SUBS_QS_SCHEMA, ?query_fun)});
|
minirest:return({ok, emqx_mgmt_api:cluster_query(Params, ?SUBS_QS_SCHEMA, ?query_fun)});
|
||||||
Topic ->
|
Topic0 ->
|
||||||
minirest:return({ok, emqx_mgmt:list_subscriptions_via_topic(emqx_mgmt_util:urldecode(Topic), ?format_fun)})
|
Topic = emqx_mgmt_util:urldecode(Topic0),
|
||||||
|
Data = emqx_mgmt:list_subscriptions_via_topic(Topic, ?format_fun),
|
||||||
|
minirest:return({ok, add_meta(Params, Data)})
|
||||||
end;
|
end;
|
||||||
|
|
||||||
list(#{node := Node} = Bindings, Params) ->
|
list(#{node := Node} = Bindings, Params) ->
|
||||||
|
@ -80,10 +82,26 @@ list(#{node := Node} = Bindings, Params) ->
|
||||||
Res -> Res
|
Res -> Res
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
Topic ->
|
Topic0 ->
|
||||||
minirest:return({ok, emqx_mgmt:list_subscriptions_via_topic(Node, emqx_mgmt_util:urldecode(Topic), ?format_fun)})
|
Topic = emqx_mgmt_util:urldecode(Topic0),
|
||||||
|
Data = emqx_mgmt:list_subscriptions_via_topic(Node, Topic, ?format_fun),
|
||||||
|
minirest:return({ok, add_meta(Params, Data)})
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
add_meta(Params, List) ->
|
||||||
|
Page = emqx_mgmt_api:page(Params),
|
||||||
|
Limit = emqx_mgmt_api:limit(Params),
|
||||||
|
Data = lists:sublist(List, (Page - 1) * Limit + 1, Limit),
|
||||||
|
#{meta => #{
|
||||||
|
page => Page,
|
||||||
|
limit => Limit,
|
||||||
|
hasnext => erlang:length(Data) >= Limit,
|
||||||
|
count => erlang:length(List)
|
||||||
|
},
|
||||||
|
data => Data,
|
||||||
|
code => 0
|
||||||
|
}.
|
||||||
|
|
||||||
lookup(#{node := Node, clientid := ClientId}, _Params) ->
|
lookup(#{node := Node, clientid := ClientId}, _Params) ->
|
||||||
minirest:return({ok, emqx_mgmt:lookup_subscriptions(Node, emqx_mgmt_util:urldecode(ClientId), ?format_fun)});
|
minirest:return({ok, emqx_mgmt:lookup_subscriptions(Node, emqx_mgmt_util:urldecode(ClientId), ?format_fun)});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue