Skip to content

Commit

Permalink
Return only latest artefacts to frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
nadzyah committed Jun 16, 2023
1 parent 61a2a1c commit eb8c565
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions backend/test_observer/controllers/families/families.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

0 comments on commit eb8c565

Please sign in to comment.