From e44212e64239032ef97f8d7fdbd171b71e5a1548 Mon Sep 17 00:00:00 2001 From: GotthardG <51994228+GotthardG@users.noreply.github.com> Date: Wed, 11 Dec 2024 16:35:01 +0100 Subject: [PATCH] get puck events --- backend/app/routers/puck.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/backend/app/routers/puck.py b/backend/app/routers/puck.py index bbb32b6..6f08479 100644 --- a/backend/app/routers/puck.py +++ b/backend/app/routers/puck.py @@ -3,7 +3,7 @@ from sqlalchemy.orm import Session from typing import List import uuid from app.schemas import Puck as PuckSchema, PuckCreate, PuckUpdate, SetTellPosition, PuckEvent -from app.models import Puck as PuckModel, Sample as SampleModel, PuckEvent as PuckEventModel +from app.models import Puck as PuckModel, Sample as SampleModel, PuckEvent as PuckEventModel, Slot as SlotModel from app.dependencies import get_db from datetime import datetime @@ -129,15 +129,21 @@ async def get_last_tell_position(puck_id: str, db: Session = Depends(get_db)): } @router.get("/pucks/slot/{slot_id}", response_model=List[PuckSchema]) -async def get_pucks_by_slot(slot_id: int, db: Session = Depends(get_db)): +async def get_pucks_by_dewar_slot(slot_id: int, db: Session = Depends(get_db)): """ - Retrieve all pucks for a given slot_id + Retrieve all pucks for a given slot_id by finding the associated dewar. """ - # Query for the pucks associated with the slot_id - pucks = db.query(PuckModel).filter(PuckModel.puck_location_in_dewar == slot_id).all() + # Query the Slot table to get the associated dewar based on slot_id + slot = db.query(SlotModel).filter(SlotModel.id == slot_id).first() + if not slot: + raise HTTPException(status_code=404, detail="Slot not found") - # If no pucks found, return an empty list - if not pucks: - return [] + # Check if the slot has a dewar associated + if not slot.dewar: + return [] # Return an empty list if no dewar is associated + # Retrieve all pucks associated with the dewar + pucks = db.query(PuckModel).filter(PuckModel.dewar_id == slot.dewar.id).all() + + # Return the list of pucks (empty if no pucks are found) return pucks \ No newline at end of file