Merge pull request #1422 from Nicholas2015/hotfix_subscriber_494

add page info to subscriber service
This commit is contained in:
Fury Zhu 2019-06-24 10:14:48 +08:00 committed by GitHub
commit c242c920b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -376,6 +376,10 @@ public class ServiceController {
*/
@RequestMapping(value = "/subscribers", method = RequestMethod.GET)
public JSONObject subscribers(HttpServletRequest request) {
int pageNo = NumberUtils.toInt(WebUtils.required(request, "pageNo"));
int pageSize = NumberUtils.toInt(WebUtils.required(request, "pageSize"));
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
Constants.DEFAULT_NAMESPACE_ID);
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
@ -385,7 +389,23 @@ public class ServiceController {
try {
List<Subscriber> subscribers = subscribeManager.getSubscribers(serviceName, namespaceId, aggregation);
result.put("subscribers", subscribers);
int start = (pageNo - 1) * pageSize;
int end = start + pageSize;
int count = subscribers.size();
if (start < 0) {
start = 0;
}
if (end > count) {
end = count;
}
result.put("subscribers", subscribers.subList(start, end));
result.put("count", count);
return result;
} catch (InterruptedException e) {