diff --git a/backend/test_observer/controllers/families/families.py b/backend/test_observer/controllers/families/families.py index 01f5f2be..986576f9 100644 --- a/backend/test_observer/controllers/families/families.py +++ b/backend/test_observer/controllers/families/families.py @@ -14,6 +14,7 @@ from sqlalchemy.orm import Session from test_observer.data_access.models import Family from test_observer.data_access.setup import get_db +from test_observer.data_access.repository import get_artefacts_by_family_name from .models import FamilyDTO @@ -27,5 +28,14 @@ def read_family(family_name: str, db: Session = Depends(get_db)): if family is None: raise HTTPException(status_code=404, detail="Family not found") + latest_artefacts = get_artefacts_by_family_name(db, family_name, latest_only=True) + + stage_artefact_dict = {stage.id: [] for stage in family.stages} + for artefact in latest_artefacts: + stage_artefact_dict[artefact.stage_id].append(artefact) + + for stage in family.stages: + stage.artefacts = stage_artefact_dict[stage.id] + family.stages = sorted(family.stages, key=lambda x: x.position) return family