getLastEndedSession method
Returns the most recent ended session for the given topic and session type, or null if none exists. Used to display past conversations.
Implementation
Future<LearningSessionModel?> getLastEndedSession({
required String topicId,
required String sessionType,
}) async {
final userId = _client.auth.currentUser?.id;
if (userId == null) return null;
final response = await _client
.from('learning_sessions')
.select()
.eq('user_id', userId)
.eq('topic_id', topicId)
.eq('session_type', sessionType)
.not('ended_at', 'is', null)
.order('ended_at', ascending: false)
.limit(1)
.maybeSingle();
if (response == null) return null;
return LearningSessionModel.fromJson(response);
}