File size: 1,374 Bytes
67f3964
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 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