outgoing by scanning the outgoing qr code

This commit is contained in:
GotthardG 2024-12-02 13:36:48 +01:00
parent 7d5e86932d
commit 1798c480f6
2 changed files with 37 additions and 5 deletions

View File

@ -79,39 +79,63 @@ async def scan_dewar(event_data: LogisticsEventCreate, db: Session = Depends(get
location_qr_code = event_data.location_qr_code location_qr_code = event_data.location_qr_code
transaction_type = event_data.transaction_type transaction_type = event_data.transaction_type
# Validate Dewar QR Code
if not dewar_qr_code or not dewar_qr_code.strip(): if not dewar_qr_code or not dewar_qr_code.strip():
logger.error("Dewar QR Code is null or empty") logger.error("Dewar QR Code is null or empty")
raise HTTPException(status_code=422, detail="Dewar QR Code cannot be null or empty") raise HTTPException(status_code=422, detail="Dewar QR Code cannot be null or empty")
# Retrieve the Dewar
dewar = db.query(DewarModel).filter(DewarModel.unique_id == dewar_qr_code).first() dewar = db.query(DewarModel).filter(DewarModel.unique_id == dewar_qr_code).first()
if not dewar: if not dewar:
logger.error("Dewar not found")
raise HTTPException(status_code=404, detail="Dewar not found") raise HTTPException(status_code=404, detail="Dewar not found")
slot = db.query(SlotModel).filter(SlotModel.qr_code == location_qr_code).first() # Check for Outgoing QR Codes and set transaction type
if location_qr_code in ["Outgoing X10-SA", "Outgoing X06-SA"]:
transaction_type = 'outgoing'
# Retrieve the Slot associated with the Dewar (for outgoing)
slot = None
if transaction_type == 'outgoing':
slot = db.query(SlotModel).filter(SlotModel.dewar_unique_id == dewar.unique_id).first()
if not slot:
logger.error(f"No slot associated with dewar for outgoing: {dewar_qr_code}")
raise HTTPException(status_code=404, detail="No slot associated with dewar for outgoing")
# Incoming Logic
if transaction_type == 'incoming': if transaction_type == 'incoming':
slot = db.query(SlotModel).filter(SlotModel.qr_code == location_qr_code).first()
if not slot or slot.occupied: if not slot or slot.occupied:
logger.error(f"Slot not found or already occupied: {slot}") logger.error(f"Slot not found or already occupied: {location_qr_code}")
raise HTTPException(status_code=400, detail="Slot not found or already occupied") raise HTTPException(status_code=400, detail="Slot not found or already occupied")
slot.dewar_unique_id = dewar.unique_id slot.dewar_unique_id = dewar.unique_id
slot.occupied = True slot.occupied = True
elif transaction_type == 'outgoing': elif transaction_type == 'outgoing':
if not slot or not slot.occupied or slot.dewar_unique_id != dewar.unique_id: if not slot.occupied or slot.dewar_unique_id != dewar.unique_id:
logger.error(f"Slot not found or dewar not associated with slot: {slot}") logger.error(f"Slot not valid for outgoing: {location_qr_code}")
raise HTTPException(status_code=400, detail="Slot not found or dewar not associated with slot") raise HTTPException(status_code=400, detail="Dewar not associated with the slot for outgoing")
slot.dewar_unique_id = None slot.dewar_unique_id = None
slot.occupied = False slot.occupied = False
elif transaction_type == 'beamline': elif transaction_type == 'beamline':
slot = db.query(SlotModel).filter(SlotModel.qr_code == location_qr_code).first()
if not slot: if not slot:
logger.error(f"Beamline location not found: {location_qr_code}") logger.error(f"Beamline location not found: {location_qr_code}")
raise HTTPException(status_code=400, detail="Beamline location not found") raise HTTPException(status_code=400, detail="Beamline location not found")
dewar.beamline_location = location_qr_code dewar.beamline_location = location_qr_code
logger.info(f"Dewar {dewar_qr_code} assigned to beamline {location_qr_code}") logger.info(f"Dewar {dewar_qr_code} assigned to beamline {location_qr_code}")
# Log the event
log_event(db, dewar.id, slot.id if slot else None, transaction_type) log_event(db, dewar.id, slot.id if slot else None, transaction_type)
db.commit() db.commit()
logger.info(
f"Transaction completed: {transaction_type} for dewar {dewar_qr_code} in slot {slot.qr_code if slot else 'N/A'}")
return {"message": "Status updated successfully"} return {"message": "Status updated successfully"}
@router.get("/slots", response_model=List[SlotSchema]) @router.get("/slots", response_model=List[SlotSchema])
async def get_all_slots(db: Session = Depends(get_db)): async def get_all_slots(db: Session = Depends(get_db)):
slots = db.query(SlotModel).options(joinedload(SlotModel.dewar)).all() slots = db.query(SlotModel).options(joinedload(SlotModel.dewar)).all()

View File

@ -4,6 +4,14 @@ from pydantic import BaseModel, EmailStr, constr, Field
from datetime import date from datetime import date
class loginToken(BaseModel):
access_token: str
token_type: str
class loginData(BaseModel):
username: str
pgroups: List[int]
class DewarTypeBase(BaseModel): class DewarTypeBase(BaseModel):
dewar_type: str dewar_type: str