getTasks method

  1. @override
Future<List<MoodleTask>> getTasks(
  1. String token, {
  2. int? courseId,
})
override

Fetches all tasks.

If courseId is provided, only tasks for that course are fetched.

Implementation

@override
Future<List<MoodleTask>> getTasks(String token, {int? courseId}) async {
  final all = courseId == null;

  log(all ? 'Fetching all tasks' : 'Fetching tasks for course with id $courseId');

  try {
    final response = await _apiService.callFunction(
      token: token,
      function: all ? 'local_lbplanner_modules_get_all_modules' : 'local_lbplanner_modules_get_all_course_modules',
      body: {
        'courseid': courseId,
      },
    );

    response.assertList();

    log('Fetched ${response.asList.length} tasks');

    return response.asList.map(MoodleTask.fromJson).toList();
  } catch (e, s) {
    log(all ? 'Failed to fetch all tasks' : 'Failed to fetch tasks for course with id $courseId', e, s);
    rethrow;
  }
}