diff --git a/src/controllers/pattern.py b/src/controllers/pattern.py index 6e8c3e2..510f468 100644 --- a/src/controllers/pattern.py +++ b/src/controllers/pattern.py @@ -1,10 +1,32 @@ from microdot import Microdot from models.pattern import Pattern import json +import sys controller = Microdot() patterns = Pattern() +def load_pattern_definitions(): + """Load pattern definitions from pattern.json file.""" + try: + # Try different paths for local development vs MicroPython + paths = ['db/pattern.json', 'pattern.json', '/db/pattern.json'] + for path in paths: + try: + with open(path, 'r') as f: + return json.load(f) + except OSError: + continue + return {} + except Exception as e: + print(f"Error loading pattern.json: {e}") + return {} + +@controller.get('/definitions') +async def get_pattern_definitions(request): + """Get pattern definitions from pattern.json.""" + definitions = load_pattern_definitions() + return json.dumps(definitions), 200, {'Content-Type': 'application/json'} @controller.get('') async def list_patterns(request):