getRecentSessions method

Future<List<LearningSessionModel>> getRecentSessions({
  1. int limit = 10,
})

Implementation

Future<List<LearningSessionModel>> getRecentSessions({int limit = 10}) async {
  final userId = _client.auth.currentUser?.id;
  if (userId == null) return [];

  final response = await _client
      .from('learning_sessions')
      .select()
      .eq('user_id', userId)
      .order('started_at', ascending: false)
      .limit(limit);
  return (response as List<dynamic>)
      .map(
        (row) => LearningSessionModel.fromJson(row as Map<String, dynamic>),
      )
      .toList();
}