feat(validation): add editing versioning revalidation and aligned reports

This commit is contained in:
Schubert Ferenc 2026-07-11 10:26:18 +02:00
parent f73a24df13
commit 302e542fda
28 changed files with 2691 additions and 406 deletions

View file

@ -1,6 +1,7 @@
from __future__ import annotations
from typing import TypeVar
from uuid import UUID
from sqlalchemy.orm import Session
@ -41,16 +42,33 @@ class CrudService:
}
def create(self, data: dict) -> ModelT:
data = self._normalize(data)
return self.repository.add(self.repository.model(**data))
def update(self, item_id: str, data: dict) -> ModelT:
data = self._normalize(data)
item = self.repository.get(item_id)
if item is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Resource not found")
if isinstance(item, Validation) and item.status in {"FREIGEGEBEN", "ABGESCHLOSSEN"}:
raise HTTPException(status_code=status.HTTP_409_CONFLICT, detail="Freigegebene oder abgeschlossene Validierungen sind schreibgeschuetzt")
for key, value in data.items():
setattr(item, key, value)
return item
def _normalize(self, data: dict) -> dict:
normalized = {}
for key, value in data.items():
if key.endswith("_id") and value == "":
normalized[key] = None
elif isinstance(value, UUID):
normalized[key] = str(value)
elif isinstance(value, list):
normalized[key] = [str(item) if isinstance(item, UUID) else item for item in value]
else:
normalized[key] = value
return normalized
def delete(self, item_id: str) -> None:
item = self.repository.get(item_id)
if item is None: