from fastapi import APIRouter, Depends, Query from typing import List from app.core.security import get_current_user, User from app.services.shortcuts import ShortcutsService, ServiceShortcut router = APIRouter() @router.get("/", response_model=List[ServiceShortcut]) async def get_all_shortcuts(): """Récupère tous les raccourcis (PUBLIC)""" try: return ShortcutsService.get_all_shortcuts() except Exception as e: return {"error": str(e)} @router.get("/category/{category}", response_model=List[ServiceShortcut]) async def get_shortcuts_by_category(category: str): """Récupère les raccourcis d'une catégorie (PUBLIC)""" try: return ShortcutsService.get_shortcuts_by_category(category) except Exception as e: return {"error": str(e)} @router.post("/", response_model=ServiceShortcut) async def create_shortcut( shortcut: ServiceShortcut, current_user: User = Depends(get_current_user) ): """Crée un nouveau raccourci""" try: return ShortcutsService.add_shortcut(shortcut) except Exception as e: return {"error": str(e)} @router.put("/{shortcut_id}", response_model=ServiceShortcut) async def update_shortcut( shortcut_id: str, shortcut: ServiceShortcut, current_user: User = Depends(get_current_user) ): """Met à jour un raccourci""" try: return ShortcutsService.update_shortcut(shortcut_id, shortcut) except Exception as e: return {"error": str(e)} @router.delete("/{shortcut_id}") async def delete_shortcut( shortcut_id: str, current_user: User = Depends(get_current_user) ): """Supprime un raccourci""" try: return ShortcutsService.delete_shortcut(shortcut_id) except Exception as e: return {"error": str(e)} @router.post("/reorder") async def reorder_shortcuts( shortcut_ids: List[str] = Query(..., description="IDs des raccourcis dans le nouvel ordre"), current_user: User = Depends(get_current_user) ): """Réordonne les raccourcis""" try: return ShortcutsService.reorder_shortcuts(shortcut_ids) except Exception as e: return {"error": str(e)} @router.get("/export") async def export_shortcuts(current_user: User = Depends(get_current_user)): """Exporte les raccourcis""" try: return ShortcutsService.export_shortcuts() except Exception as e: return {"error": str(e)} @router.post("/import") async def import_shortcuts( shortcuts: List[dict], current_user: User = Depends(get_current_user) ): """Importe des raccourcis""" try: return ShortcutsService.import_shortcuts(shortcuts) except Exception as e: return {"error": str(e)}