micro-learn / data /paths.py
ldrissi's picture
finish the idea of micro learning part 2
67f3964
# In data/paths.py
import firebase_admin
from firebase_admin import firestore
class LearningPathManager:
def __init__(self):
self.db = firestore.client()
self.collection = self.db.collection('learning_paths')
def create_path(self, path_data):
"""Create a new learning path"""
doc_ref = self.collection.document()
doc_ref.set(path_data)
return doc_ref.id
def get_path(self, path_id):
"""Get learning path by ID"""
doc = self.collection.document(path_id).get()
return doc.to_dict() if doc.exists else None
def get_all_paths(self):
"""Get all learning paths"""
docs = self.collection.stream()
return [doc.to_dict() for doc in docs]
def add_module_to_path(self, path_id, module_id, position=None):
"""Add a module to a learning path"""
path = self.get_path(path_id)
if not path:
return False
if 'modules' not in path:
path['modules'] = []
if position is None or position >= len(path['modules']):
path['modules'].append(module_id)
else:
path['modules'].insert(position, module_id)
self.collection.document(path_id).update({
'modules': path['modules']
})
return True