getConsultationList method

Future<List<Consultation>> getConsultationList({
  1. int page = 1,
  2. int perPage = 20,
  3. int? userId,
})

Retrieves a list of consultations from the API.

page - The page number of the consultations to retrieve. Defaults to 1. perPage - The number of consultations to retrieve per page. Defaults to 20.

Returns a list of consultation objects if the API call is successful.

Implementation

Future<List<Consultation>> getConsultationList(
    {int page = 1, int perPage = 20, int? userId}) async {
  Map<String, dynamic> body = {
    "expand":
        "pusherAppKey,parentConsultation,consultations,user,media,pusherChannel,"
            "chatConfig,chatHistory,voipConfig,videoConfig,recommendation"
  };
  if (userId != null) {
    body["filter[user_id]"] = userId;
  }
  final response = await callApi(
      perPage: perPage,
      page: page,
      endpoint: 'consultations',
      method: 'get',
      body: body);

  if (response.statusCode == 200) {
    final List<dynamic> responseData = json.decode(response.body);
    final List<Consultation> consultations =
        responseData.map((json) => Consultation.fromJson(json)).toList();
    return consultations;
  } else {
    throw Exception(response);
  }
}