Add member count to each group returned by GET /groups (expanded on code written by QuickMythril)

This commit is contained in:
CalDescent 2022-04-15 10:19:43 +01:00
parent ad31d8014d
commit fee603e500

View File

@ -99,7 +99,13 @@ public class GroupsResource {
) @QueryParam("reverse") Boolean reverse) {
try (final Repository repository = RepositoryManager.getRepository()) {
List<GroupData> allGroupData = repository.getGroupRepository().getAllGroups(limit, offset, reverse);
// allGroupData.forEach(GroupData -> GroupData.memberCount = repository.getGroupRepository().countGroupMembers(GroupData.groupId));
allGroupData.forEach(groupData -> {
try {
groupData.memberCount = repository.getGroupRepository().countGroupMembers(groupData.getGroupId());
} catch (DataException e) {
// Exclude memberCount for this group
}
});
return allGroupData;
} catch (DataException e) {
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);