getTopicTree method

Future<List<TopicModel>> getTopicTree(
  1. String domainId
)

Fetch all topics for a domain and build a tree using parent_topic_id.

Implementation

Future<List<TopicModel>> getTopicTree(String domainId) async {
  final response = await _client
      .from('topics')
      .select()
      .eq('domain_id', domainId)
      .order('sort_order', ascending: true);
  final flat = (response as List<dynamic>)
      .map((row) => TopicModel.fromJson(row as Map<String, dynamic>))
      .toList();
  return TopicModel.buildTree(flat);
}