Update beamtime assignment logic for pucks and samples

Simplified and unified beamtime assignment handling for pucks and samples in the backend. Enhanced the frontend to display detailed assignment state, including shift, date, and beamline, for both pucks and dewars. This ensures consistent and accurate state management across the application.
This commit is contained in:
GotthardG
2025-05-07 09:39:40 +02:00
parent 9e5734f060
commit e341459590
3 changed files with 89 additions and 30 deletions

View File

@ -595,14 +595,23 @@ async def assign_beamtime_to_dewar(
db: Session = Depends(get_db),
):
dewar = db.query(DewarModel).filter(DewarModel.id == dewar_id).first()
if not dewar: # <- Move check earlier!
if not dewar:
raise HTTPException(status_code=404, detail="Dewar not found")
if beamtime_id == 0:
dewar.beamtime_id = None
else:
dewar.beamtime_id = beamtime_id
dewar.beamtime_id = None if beamtime_id == 0 else beamtime_id
db.commit()
db.refresh(dewar)
for puck in dewar.pucks:
puck.beamtime_id = None if beamtime_id == 0 else beamtime_id
for sample in puck.samples:
has_sample_event = (
db.query(SampleEvent).filter(SampleEvent.sample_id == sample.id).count()
> 0
)
if not has_sample_event:
sample.beamtime_id = None if beamtime_id == 0 else beamtime_id
db.commit()
return {"status": "success", "dewar_id": dewar.id, "beamtime_id": beamtime_id}