get puck events
This commit is contained in:
parent
ed84060563
commit
e44212e642
@ -3,7 +3,7 @@ from sqlalchemy.orm import Session
|
|||||||
from typing import List
|
from typing import List
|
||||||
import uuid
|
import uuid
|
||||||
from app.schemas import Puck as PuckSchema, PuckCreate, PuckUpdate, SetTellPosition, PuckEvent
|
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 app.dependencies import get_db
|
||||||
from datetime import datetime
|
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])
|
@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
|
# Query the Slot table to get the associated dewar based on slot_id
|
||||||
pucks = db.query(PuckModel).filter(PuckModel.puck_location_in_dewar == slot_id).all()
|
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
|
# Check if the slot has a dewar associated
|
||||||
if not pucks:
|
if not slot.dewar:
|
||||||
return []
|
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
|
return pucks
|
Loading…
x
Reference in New Issue
Block a user