fix(knowledge): improve upload workflow and seed manufacturers

This commit is contained in:
Schubert Ferenc 2026-07-03 18:40:05 +02:00
parent 964b545bc5
commit 612e1ad8ed
13 changed files with 429 additions and 20 deletions

View file

@ -125,7 +125,7 @@ class KnowledgeService:
file: UploadFile,
payload: KnowledgeDocumentCreate,
) -> KnowledgeDocument:
KnowledgeService._validate_document_links(db, payload.manufacturer_id, payload.device_id)
KnowledgeService._validate_upload_links(db, payload.manufacturer_id, payload.device_id)
storage_service = get_storage_service()
max_bytes = storage_service.max_upload_mb * 1024 * 1024
content = await file.read(max_bytes + 1)
@ -208,6 +208,8 @@ class KnowledgeService:
@staticmethod
def _validate_document_links(db: Session, manufacturer_id: int, device_id: int | None) -> None:
if not manufacturer_id:
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Bitte wählen Sie einen Hersteller aus.")
if KnowledgeRepository.get_manufacturer(db, manufacturer_id) is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Hersteller nicht gefunden")
if device_id is not None:
@ -227,3 +229,23 @@ class KnowledgeService:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Gerät nicht gefunden")
if manufacturer_id is not None and device.manufacturer_id != manufacturer_id:
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Gerät gehört nicht zum Hersteller")
@staticmethod
def _validate_upload_links(db: Session, manufacturer_id: int, device_id: int | None) -> None:
if not manufacturer_id:
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Bitte wählen Sie einen Hersteller aus.")
if device_id is None:
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Bitte wählen Sie ein Gerät aus.")
manufacturer = KnowledgeRepository.get_manufacturer(db, manufacturer_id)
if manufacturer is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Der ausgewählte Hersteller existiert nicht.")
device = KnowledgeRepository.get_device(db, device_id)
if device is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Das ausgewählte Gerät existiert nicht.")
if device.manufacturer_id != manufacturer_id:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="Das ausgewählte Gerät gehört nicht zum ausgewählten Hersteller.",
)