retrieve pucks that are in the tell dewar
This commit is contained in:
parent
6c88ff9651
commit
530c9efae0
@ -132,10 +132,6 @@ async def scan_dewar(event_data: LogisticsEventCreate, db: Session = Depends(get
|
||||
|
||||
return {"message": "Status updated successfully"}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@router.get("/slots", response_model=List[SlotSchema])
|
||||
async def get_all_slots(db: Session = Depends(get_db)):
|
||||
slots = db.query(SlotModel).options(joinedload(SlotModel.dewar)).all()
|
||||
|
@ -18,6 +18,55 @@ async def get_pucks(db: Session = Depends(get_db)):
|
||||
return db.query(PuckModel).all()
|
||||
|
||||
|
||||
@router.get("/with-tell-position", response_model=List[dict])
|
||||
async def get_pucks_with_tell_position(db: Session = Depends(get_db)):
|
||||
"""
|
||||
Retrieve all pucks with a `tell_position` set (not null) and their associated samples.
|
||||
"""
|
||||
# Query all pucks that have an event with a non-null tell_position
|
||||
pucks = (
|
||||
db.query(PuckModel)
|
||||
.join(PuckEventModel, PuckModel.id == PuckEventModel.puck_id)
|
||||
.filter(PuckEventModel.tell_position.isnot(None))
|
||||
.all()
|
||||
)
|
||||
logger.info(f"Pucks with tell position: {pucks}")
|
||||
|
||||
if not pucks:
|
||||
logger.info("No pucks with tell_position found.") # Log for debugging
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail="No pucks with a `tell_position` found."
|
||||
)
|
||||
|
||||
result = []
|
||||
|
||||
for puck in pucks:
|
||||
# Get associated samples for the puck
|
||||
samples = db.query(SampleModel).filter(SampleModel.puck_id == puck.id).all()
|
||||
sample_data = [
|
||||
{
|
||||
"id": sample.id,
|
||||
"sample_name": sample.sample_name,
|
||||
"position": sample.position, # Updated field based on schema
|
||||
}
|
||||
for sample in samples
|
||||
]
|
||||
|
||||
# Add puck and sample info to the result
|
||||
result.append(
|
||||
{
|
||||
"id": puck.id,
|
||||
"puck_name": puck.puck_name,
|
||||
"puck_type": puck.puck_type,
|
||||
"puck_location_in_dewar": puck.puck_location_in_dewar,
|
||||
"dewar_id": puck.dewar_id,
|
||||
"samples": sample_data, # Add associated samples
|
||||
}
|
||||
)
|
||||
|
||||
return result
|
||||
|
||||
@router.get("/{puck_id}", response_model=PuckSchema)
|
||||
async def get_puck(puck_id: str, db: Session = Depends(get_db)):
|
||||
puck = db.query(PuckModel).filter(PuckModel.id == puck_id).first()
|
||||
|
Loading…
x
Reference in New Issue
Block a user