listUniqueUsersWithGrants method

Future<List<ProjectUserGrantCount>> listUniqueUsersWithGrants({
  1. required String projectId,
  2. int limit = 50,
  3. int offset = 0,
})

GET /accounts/projects/{project_id}/room-grants/by-user?limit=&offset=

Implementation

Future<List<ProjectUserGrantCount>> listUniqueUsersWithGrants({required String projectId, int limit = 50, int offset = 0}) async {
  var uri = Uri.parse(
    '$baseUrl/accounts/projects/$projectId/room-grants/by-user',
  ).replace(queryParameters: {'limit': '$limit', 'offset': '$offset'});

  final response = await http.get(uri, headers: _getHeaders());

  if (response.statusCode >= 400) {
    throw MeshagentException(
      'Failed to list unique users with grants. '
      'Status code: ${response.statusCode}, body: ${response.body}',
    );
  }

  final data = jsonDecode(response.body) as Map<String, dynamic>;
  final list = data['users'] as List<dynamic>? ?? [];
  return list.whereType<Map<String, dynamic>>().map(ProjectUserGrantCount.fromJson).toList();
}