listUniqueRoomsWithGrants method

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

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

Implementation

Future<List<ProjectRoomGrantCount>> listUniqueRoomsWithGrants({required String projectId, int limit = 50, int offset = 0}) async {
  final encodedProjectId = Uri.encodeComponent(projectId);
  final uri = Uri.parse(
    '$baseUrl/accounts/projects/$encodedProjectId/room-grants/by-room',
  ).replace(queryParameters: {'limit': '$limit', 'offset': '$offset'});
  final response = await httpClient.get(uri);

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

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