updated models and schemas for shipments and dewars
This commit is contained in:
parent
d5c7e7e6f3
commit
701c42c0dd
@ -14,23 +14,23 @@ def get_shipments(db: Session):
|
||||
logging.info(f"Total of {len(shipments)} shipments fetched.")
|
||||
for shipment in shipments:
|
||||
if shipment.proposal_id is None:
|
||||
logging.warning(f"Shipment {shipment.shipment_id} is missing proposal ID.")
|
||||
logging.debug(f"Shipment ID: {shipment.shipment_id}, Shipment Name: {shipment.shipment_name}")
|
||||
logging.warning(f"Shipment {shipment.id} is missing proposal ID.")
|
||||
logging.debug(f"Shipment ID: {shipment.id}, Shipment Name: {shipment.shipment_name}")
|
||||
return shipments
|
||||
|
||||
|
||||
def get_shipment_by_id(db: Session, shipment_id: str):
|
||||
logging.info(f"Fetching shipment with ID: {shipment_id}")
|
||||
def get_shipment_by_id(db: Session, id: int):
|
||||
logging.info(f"Fetching shipment with ID: {id}")
|
||||
shipment = db.query(Shipment).options(
|
||||
joinedload(Shipment.contact_person),
|
||||
joinedload(Shipment.return_address),
|
||||
joinedload(Shipment.proposal),
|
||||
joinedload(Shipment.dewars)
|
||||
).filter(Shipment.shipment_id == shipment_id).first()
|
||||
).filter(Shipment.id == id).first()
|
||||
if shipment:
|
||||
if shipment.proposal_id is None:
|
||||
logging.warning(f"Shipment {shipment.shipment_id} is missing proposal ID.")
|
||||
logging.warning(f"Shipment {shipment.id} is missing proposal ID.")
|
||||
logging.info(f"Shipment found: {shipment}")
|
||||
else:
|
||||
logging.warning(f"Shipment with ID {shipment_id} not found.")
|
||||
logging.warning(f"Shipment with ID {id} not found.")
|
||||
return shipment
|
@ -35,31 +35,31 @@ return_addresses = [
|
||||
|
||||
dewars = [
|
||||
Dewar(
|
||||
id='DEWAR001', dewar_name='Dewar One', tracking_number='TRACK123',
|
||||
id=1, dewar_name='Dewar One', tracking_number='TRACK123',
|
||||
return_address_id=1, contact_person_id=1, status='Ready for Shipping',
|
||||
ready_date=datetime.strptime('2023-09-30', '%Y-%m-%d'), shipping_date=None, arrival_date=None,
|
||||
returning_date=None, qrcode='QR123DEWAR001',
|
||||
),
|
||||
Dewar(
|
||||
id='DEWAR002', dewar_name='Dewar Two', tracking_number='TRACK124',
|
||||
id=2, dewar_name='Dewar Two', tracking_number='TRACK124',
|
||||
return_address_id=2, contact_person_id=2, status='In Preparation',
|
||||
ready_date=None, shipping_date=None, arrival_date=None, returning_date=None, qrcode='QR123DEWAR002',
|
||||
),
|
||||
Dewar(
|
||||
id='DEWAR003', dewar_name='Dewar Three', tracking_number='TRACK125',
|
||||
id=3, dewar_name='Dewar Three', tracking_number='TRACK125',
|
||||
return_address_id=1, contact_person_id=3, status='Not Shipped',
|
||||
ready_date=datetime.strptime('2024-01-01', '%Y-%m-%d'), shipping_date=None, arrival_date=None,
|
||||
returning_date=None, qrcode='QR123DEWAR003',
|
||||
),
|
||||
Dewar(
|
||||
id='DEWAR004', dewar_name='Dewar Four', tracking_number='',
|
||||
id=4, dewar_name='Dewar Four', tracking_number='',
|
||||
return_address_id=1, contact_person_id=3, status='Delayed',
|
||||
ready_date=datetime.strptime('2024-01-01', '%Y-%m-%d'),
|
||||
shipping_date=datetime.strptime('2024-01-02', '%Y-%m-%d'),
|
||||
arrival_date=None, returning_date=None, qrcode='QR123DEWAR004',
|
||||
),
|
||||
Dewar(
|
||||
id='DEWAR005', dewar_name='Dewar Five', tracking_number='',
|
||||
id=5, dewar_name='Dewar Five', tracking_number='',
|
||||
return_address_id=1, contact_person_id=3, status='Returned',
|
||||
arrival_date=datetime.strptime('2024-01-03', '%Y-%m-%d'),
|
||||
returning_date=datetime.strptime('2024-01-07', '%Y-%m-%d'),
|
||||
@ -75,9 +75,9 @@ proposals = [
|
||||
Proposal(id=5, number="PROPOSAL-MORDOR-005"),
|
||||
]
|
||||
|
||||
specific_dewar_ids1 = ['DEWAR003']
|
||||
specific_dewar_ids2 = ['DEWAR001', 'DEWAR002']
|
||||
specific_dewar_ids3 = ['DEWAR003', 'DEWAR004', 'DEWAR005']
|
||||
specific_dewar_ids1 = [5]
|
||||
specific_dewar_ids2 = [1, 2]
|
||||
specific_dewar_ids3 = [3, 4]
|
||||
|
||||
specific_dewars1 = [dewar for dewar in dewars if dewar.id in specific_dewar_ids1]
|
||||
specific_dewars2 = [dewar for dewar in dewars if dewar.id in specific_dewar_ids2]
|
||||
@ -85,53 +85,53 @@ specific_dewars3 = [dewar for dewar in dewars if dewar.id in specific_dewar_ids3
|
||||
|
||||
shipments = [
|
||||
Shipment(
|
||||
shipment_id=1, shipment_date=datetime.strptime('2024-10-10', '%Y-%m-%d'),
|
||||
id=1, shipment_date=datetime.strptime('2024-10-10', '%Y-%m-%d'),
|
||||
shipment_name='Shipment from Mordor', shipment_status='Delivered', contact_person_id=2,
|
||||
proposal_id=3, return_address_id=1, comments='Handle with care', dewars=specific_dewars1
|
||||
),
|
||||
Shipment(
|
||||
shipment_id=2, shipment_date=datetime.strptime('2024-10-24', '%Y-%m-%d'),
|
||||
id=2, shipment_date=datetime.strptime('2024-10-24', '%Y-%m-%d'),
|
||||
shipment_name='Shipment from Mordor', shipment_status='In Transit', contact_person_id=4,
|
||||
proposal_id=4, return_address_id=2, comments='Contains the one ring', dewars=specific_dewars2
|
||||
),
|
||||
Shipment(
|
||||
shipment_id=3, shipment_date=datetime.strptime('2024-10-28', '%Y-%m-%d'),
|
||||
id=3, shipment_date=datetime.strptime('2024-10-28', '%Y-%m-%d'),
|
||||
shipment_name='Shipment from Mordor', shipment_status='In Transit', contact_person_id=5,
|
||||
proposal_id=5, return_address_id=1, comments='Contains the one ring', dewars=specific_dewars3
|
||||
),
|
||||
]
|
||||
|
||||
pucks = [
|
||||
Puck(id=1, puck_name="PUCK001", puck_type="Unipuck", puck_location_in_dewar=1, positions=[], dewar_id='DEWAR001'),
|
||||
Puck(id=2, puck_name="PUCK002", puck_type="Unipuck", puck_location_in_dewar=2, positions=[], dewar_id='DEWAR001'),
|
||||
Puck(id=3, puck_name="PUCK003", puck_type="Unipuck", puck_location_in_dewar=3, positions=[], dewar_id='DEWAR001'),
|
||||
Puck(id=4, puck_name="PUCK004", puck_type="Unipuck", puck_location_in_dewar=4, positions=[], dewar_id='DEWAR001'),
|
||||
Puck(id=5, puck_name="PUCK005", puck_type="Unipuck", puck_location_in_dewar=5, positions=[], dewar_id='DEWAR001'),
|
||||
Puck(id=6, puck_name="PUCK006", puck_type="Unipuck", puck_location_in_dewar=6, positions=[], dewar_id='DEWAR001'),
|
||||
Puck(id=7, puck_name="PUCK007", puck_type="Unipuck", puck_location_in_dewar=7, positions=[], dewar_id='DEWAR001'),
|
||||
Puck(id=8, puck_name="PK001", puck_type="Unipuck", puck_location_in_dewar=1, positions=[], dewar_id='DEWAR002'),
|
||||
Puck(id=9, puck_name="PK002", puck_type="Unipuck", puck_location_in_dewar=2, positions=[], dewar_id='DEWAR002'),
|
||||
Puck(id=10, puck_name="PK003", puck_type="Unipuck", puck_location_in_dewar=3, positions=[], dewar_id='DEWAR002'),
|
||||
Puck(id=11, puck_name="PK004", puck_type="Unipuck", puck_location_in_dewar=4, positions=[], dewar_id='DEWAR002'),
|
||||
Puck(id=12, puck_name="PK005", puck_type="Unipuck", puck_location_in_dewar=5, positions=[], dewar_id='DEWAR002'),
|
||||
Puck(id=13, puck_name="PK006", puck_type="Unipuck", puck_location_in_dewar=6, positions=[], dewar_id='DEWAR002'),
|
||||
Puck(id=14, puck_name="P001", puck_type="Unipuck", puck_location_in_dewar=1, positions=[], dewar_id='DEWAR003'),
|
||||
Puck(id=15, puck_name="P002", puck_type="Unipuck", puck_location_in_dewar=2, positions=[], dewar_id='DEWAR003'),
|
||||
Puck(id=16, puck_name="P003", puck_type="Unipuck", puck_location_in_dewar=3, positions=[], dewar_id='DEWAR003'),
|
||||
Puck(id=17, puck_name="P004", puck_type="Unipuck", puck_location_in_dewar=4, positions=[], dewar_id='DEWAR003'),
|
||||
Puck(id=18, puck_name="P005", puck_type="Unipuck", puck_location_in_dewar=5, positions=[], dewar_id='DEWAR003'),
|
||||
Puck(id=19, puck_name="P006", puck_type="Unipuck", puck_location_in_dewar=6, positions=[], dewar_id='DEWAR003'),
|
||||
Puck(id=20, puck_name="P007", puck_type="Unipuck", puck_location_in_dewar=7, positions=[], dewar_id='DEWAR003'),
|
||||
Puck(id=21, puck_name="PC002", puck_type="Unipuck", puck_location_in_dewar=2, positions=[], dewar_id='DEWAR004'),
|
||||
Puck(id=22, puck_name="PC003", puck_type="Unipuck", puck_location_in_dewar=3, positions=[], dewar_id='DEWAR004'),
|
||||
Puck(id=23, puck_name="PC004", puck_type="Unipuck", puck_location_in_dewar=4, positions=[], dewar_id='DEWAR004'),
|
||||
Puck(id=24, puck_name="PC005", puck_type="Unipuck", puck_location_in_dewar=5, positions=[], dewar_id='DEWAR004'),
|
||||
Puck(id=25, puck_name="PC006", puck_type="Unipuck", puck_location_in_dewar=6, positions=[], dewar_id='DEWAR004'),
|
||||
Puck(id=26, puck_name="PC007", puck_type="Unipuck", puck_location_in_dewar=7, positions=[], dewar_id='DEWAR004'),
|
||||
Puck(id=27, puck_name="PKK004", puck_type="Unipuck", puck_location_in_dewar=4, positions=[], dewar_id='DEWAR005'),
|
||||
Puck(id=28, puck_name="PKK005", puck_type="Unipuck", puck_location_in_dewar=5, positions=[], dewar_id='DEWAR005'),
|
||||
Puck(id=29, puck_name="PKK006", puck_type="Unipuck", puck_location_in_dewar=6, positions=[], dewar_id='DEWAR005'),
|
||||
Puck(id=30, puck_name="PKK007", puck_type="Unipuck", puck_location_in_dewar=7, positions=[], dewar_id='DEWAR005')
|
||||
Puck(id=1, puck_name="PUCK001", puck_type="Unipuck", puck_location_in_dewar=1, positions=[], dewar_id=1),
|
||||
Puck(id=2, puck_name="PUCK002", puck_type="Unipuck", puck_location_in_dewar=2, positions=[], dewar_id=1),
|
||||
Puck(id=3, puck_name="PUCK003", puck_type="Unipuck", puck_location_in_dewar=3, positions=[], dewar_id=1),
|
||||
Puck(id=4, puck_name="PUCK004", puck_type="Unipuck", puck_location_in_dewar=4, positions=[], dewar_id=1),
|
||||
Puck(id=5, puck_name="PUCK005", puck_type="Unipuck", puck_location_in_dewar=5, positions=[], dewar_id=1),
|
||||
Puck(id=6, puck_name="PUCK006", puck_type="Unipuck", puck_location_in_dewar=6, positions=[], dewar_id=1),
|
||||
Puck(id=7, puck_name="PUCK007", puck_type="Unipuck", puck_location_in_dewar=7, positions=[], dewar_id=1),
|
||||
Puck(id=8, puck_name="PK001", puck_type="Unipuck", puck_location_in_dewar=1, positions=[], dewar_id=2),
|
||||
Puck(id=9, puck_name="PK002", puck_type="Unipuck", puck_location_in_dewar=2, positions=[], dewar_id=2),
|
||||
Puck(id=10, puck_name="PK003", puck_type="Unipuck", puck_location_in_dewar=3, positions=[], dewar_id=2),
|
||||
Puck(id=11, puck_name="PK004", puck_type="Unipuck", puck_location_in_dewar=4, positions=[], dewar_id=2),
|
||||
Puck(id=12, puck_name="PK005", puck_type="Unipuck", puck_location_in_dewar=5, positions=[], dewar_id=2),
|
||||
Puck(id=13, puck_name="PK006", puck_type="Unipuck", puck_location_in_dewar=6, positions=[], dewar_id=2),
|
||||
Puck(id=14, puck_name="P001", puck_type="Unipuck", puck_location_in_dewar=1, positions=[], dewar_id=3),
|
||||
Puck(id=15, puck_name="P002", puck_type="Unipuck", puck_location_in_dewar=2, positions=[], dewar_id=3),
|
||||
Puck(id=16, puck_name="P003", puck_type="Unipuck", puck_location_in_dewar=3, positions=[], dewar_id=3),
|
||||
Puck(id=17, puck_name="P004", puck_type="Unipuck", puck_location_in_dewar=4, positions=[], dewar_id=3),
|
||||
Puck(id=18, puck_name="P005", puck_type="Unipuck", puck_location_in_dewar=5, positions=[], dewar_id=3),
|
||||
Puck(id=19, puck_name="P006", puck_type="Unipuck", puck_location_in_dewar=6, positions=[], dewar_id=3),
|
||||
Puck(id=20, puck_name="P007", puck_type="Unipuck", puck_location_in_dewar=7, positions=[], dewar_id=3),
|
||||
Puck(id=21, puck_name="PC002", puck_type="Unipuck", puck_location_in_dewar=2, positions=[], dewar_id=4),
|
||||
Puck(id=22, puck_name="PC003", puck_type="Unipuck", puck_location_in_dewar=3, positions=[], dewar_id=4),
|
||||
Puck(id=23, puck_name="PC004", puck_type="Unipuck", puck_location_in_dewar=4, positions=[], dewar_id=4),
|
||||
Puck(id=24, puck_name="PC005", puck_type="Unipuck", puck_location_in_dewar=5, positions=[], dewar_id=4),
|
||||
Puck(id=25, puck_name="PC006", puck_type="Unipuck", puck_location_in_dewar=6, positions=[], dewar_id=4),
|
||||
Puck(id=26, puck_name="PC007", puck_type="Unipuck", puck_location_in_dewar=7, positions=[], dewar_id=4),
|
||||
Puck(id=27, puck_name="PKK004", puck_type="Unipuck", puck_location_in_dewar=4, positions=[], dewar_id=5),
|
||||
Puck(id=28, puck_name="PKK005", puck_type="Unipuck", puck_location_in_dewar=5, positions=[], dewar_id=5),
|
||||
Puck(id=29, puck_name="PKK006", puck_type="Unipuck", puck_location_in_dewar=6, positions=[], dewar_id=5),
|
||||
Puck(id=30, puck_name="PKK007", puck_type="Unipuck", puck_location_in_dewar=7, positions=[], dewar_id=5)
|
||||
]
|
||||
|
||||
samples = []
|
||||
|
@ -7,7 +7,7 @@ from app.calculations import calculate_number_of_pucks, calculate_number_of_samp
|
||||
class Shipment(Base):
|
||||
__tablename__ = "shipments"
|
||||
|
||||
shipment_id = Column(Integer, primary_key=True, index=True, autoincrement=True)
|
||||
id = Column(Integer, primary_key=True, index=True, autoincrement=True)
|
||||
shipment_name = Column(String, index=True)
|
||||
shipment_date = Column(Date)
|
||||
shipment_status = Column(String)
|
||||
@ -49,7 +49,7 @@ class Address(Base):
|
||||
class Dewar(Base):
|
||||
__tablename__ = "dewars"
|
||||
|
||||
id = Column(String, primary_key=True, index=True)
|
||||
id = Column(Integer, primary_key=True, index=True, autoincrement=True)
|
||||
dewar_name = Column(String)
|
||||
tracking_number = Column(String)
|
||||
status = Column(String)
|
||||
@ -58,7 +58,7 @@ class Dewar(Base):
|
||||
arrival_date = Column(Date, nullable=True)
|
||||
returning_date = Column(Date, nullable=True)
|
||||
qrcode = Column(String)
|
||||
shipment_id = Column(String, ForeignKey("shipments.shipment_id"))
|
||||
shipment_id = Column(Integer, ForeignKey("shipments.id"))
|
||||
return_address_id = Column(Integer, ForeignKey("addresses.id"))
|
||||
contact_person_id = Column(Integer, ForeignKey("contact_persons.id"))
|
||||
|
||||
@ -92,7 +92,7 @@ class Puck(Base):
|
||||
puck_name = Column(String)
|
||||
puck_type = Column(String)
|
||||
puck_location_in_dewar = Column(Integer)
|
||||
dewar_id = Column(String, ForeignKey('dewars.id')) # Note: changed to String
|
||||
dewar_id = Column(Integer, ForeignKey('dewars.id')) # Note: changed to String
|
||||
|
||||
positions = relationship("Sample", back_populates="puck")
|
||||
dewar = relationship("Dewar", back_populates="pucks")
|
||||
|
@ -17,10 +17,7 @@ async def get_dewars(db: Session = Depends(get_db)):
|
||||
|
||||
@router.post("/", response_model=DewarSchema, status_code=status.HTTP_201_CREATED)
|
||||
async def create_dewar(dewar: DewarCreate, db: Session = Depends(get_db)) -> DewarSchema:
|
||||
dewar_id = f'DEWAR-{uuid.uuid4().hex[:8].upper()}'
|
||||
|
||||
db_dewar = DewarModel(
|
||||
id=dewar_id,
|
||||
dewar_name=dewar.dewar_name,
|
||||
tracking_number=dewar.tracking_number,
|
||||
status=dewar.status,
|
||||
|
@ -20,11 +20,11 @@ def default_serializer(obj):
|
||||
raise TypeError(f"Type {type(obj)} not serializable")
|
||||
|
||||
@router.get("", response_model=List[ShipmentSchema])
|
||||
async def fetch_shipments(shipment_id: Optional[str] = Query(None), db: Session = Depends(get_db)):
|
||||
if shipment_id:
|
||||
shipment = get_shipment_by_id(db, shipment_id)
|
||||
async def fetch_shipments(id: Optional[int] = Query(None), db: Session = Depends(get_db)):
|
||||
if id:
|
||||
shipment = get_shipment_by_id(db, id)
|
||||
if not shipment:
|
||||
logging.error(f"Shipment with ID {shipment_id} not found")
|
||||
logging.error(f"Shipment with ID {id} not found")
|
||||
raise HTTPException(status_code=404, detail="Shipment not found")
|
||||
logging.info(f"Shipment found: {shipment}")
|
||||
return [shipment]
|
||||
@ -32,7 +32,7 @@ async def fetch_shipments(shipment_id: Optional[str] = Query(None), db: Session
|
||||
shipments = get_shipments(db)
|
||||
logging.info(f"Total shipments fetched: {len(shipments)}")
|
||||
for shipment in shipments:
|
||||
logging.info(f"Shipment ID: {shipment.shipment_id}, Shipment Name: {shipment.shipment_name}")
|
||||
logging.info(f"Shipment ID: {shipment.id}, Shipment Name: {shipment.shipment_name}")
|
||||
return shipments
|
||||
|
||||
@router.post("", response_model=ShipmentSchema, status_code=status.HTTP_201_CREATED)
|
||||
@ -69,8 +69,8 @@ async def create_shipment(shipment: ShipmentCreate, db: Session = Depends(get_db
|
||||
return db_shipment
|
||||
|
||||
@router.delete("/{shipment_id}", status_code=status.HTTP_204_NO_CONTENT)
|
||||
async def delete_shipment(shipment_id: str, db: Session = Depends(get_db)):
|
||||
shipment = db.query(ShipmentModel).filter(ShipmentModel.shipment_id == shipment_id).first()
|
||||
async def delete_shipment(id: int, db: Session = Depends(get_db)):
|
||||
shipment = db.query(ShipmentModel).filter(ShipmentModel.id == id).first()
|
||||
if not shipment:
|
||||
raise HTTPException(status_code=404, detail="Shipment not found")
|
||||
db.delete(shipment)
|
||||
@ -78,10 +78,10 @@ async def delete_shipment(shipment_id: str, db: Session = Depends(get_db)):
|
||||
return
|
||||
|
||||
@router.put("/{shipment_id}", response_model=ShipmentSchema)
|
||||
async def update_shipment(shipment_id: str, updated_shipment: ShipmentCreate, db: Session = Depends(get_db)):
|
||||
async def update_shipment(id: int, updated_shipment: ShipmentCreate, db: Session = Depends(get_db)):
|
||||
print("Received payload:", json.dumps(updated_shipment.dict(), indent=2, default=default_serializer))
|
||||
|
||||
shipment = db.query(ShipmentModel).filter(ShipmentModel.shipment_id == shipment_id).first()
|
||||
shipment = db.query(ShipmentModel).filter(ShipmentModel.id == id).first()
|
||||
if not shipment:
|
||||
raise HTTPException(status_code=404, detail="Shipment not found")
|
||||
|
||||
@ -131,8 +131,8 @@ async def update_shipment(shipment_id: str, updated_shipment: ShipmentCreate, db
|
||||
|
||||
|
||||
@router.post("/{shipment_id}/add_dewar", response_model=ShipmentSchema)
|
||||
async def add_dewar_to_shipment(shipment_id: str, dewar_id: str, db: Session = Depends(get_db)):
|
||||
shipment = db.query(ShipmentModel).filter(ShipmentModel.shipment_id == shipment_id).first()
|
||||
async def add_dewar_to_shipment(id: int, dewar_id: int, db: Session = Depends(get_db)):
|
||||
shipment = db.query(ShipmentModel).filter(ShipmentModel.id == id).first()
|
||||
if not shipment:
|
||||
raise HTTPException(status_code=404, detail="Shipment not found")
|
||||
dewar = db.query(DewarModel).filter(DewarModel.id == dewar_id).first()
|
||||
@ -146,11 +146,15 @@ async def add_dewar_to_shipment(shipment_id: str, dewar_id: str, db: Session = D
|
||||
return shipment
|
||||
|
||||
@router.delete("/{shipment_id}/remove_dewar/{dewar_id}", response_model=ShipmentSchema)
|
||||
async def remove_dewar_from_shipment(shipment_id: str, dewar_id: str, db: Session = Depends(get_db)):
|
||||
shipment = db.query(ShipmentModel).filter(ShipmentModel.shipment_id == shipment_id).first()
|
||||
async def remove_dewar_from_shipment(shipment_id: int, dewar_id: int, db: Session = Depends(get_db)):
|
||||
shipment = db.query(ShipmentModel).filter(ShipmentModel.id == shipment_id).first()
|
||||
if not shipment:
|
||||
raise HTTPException(status_code=404, detail="Shipment not found")
|
||||
|
||||
dewar_exists = any(dw.id == dewar_id for dw in shipment.dewars)
|
||||
if not dewar_exists:
|
||||
raise HTTPException(status_code=404, detail=f"Dewar with ID {dewar_id} not found in shipment")
|
||||
|
||||
shipment.dewars = [dw for dw in shipment.dewars if dw.id != dewar_id]
|
||||
db.commit()
|
||||
db.refresh(shipment)
|
||||
@ -162,8 +166,8 @@ async def get_shipment_contact_persons(db: Session = Depends(get_db)):
|
||||
return contact_persons
|
||||
|
||||
@router.get("/{shipment_id}/samples", response_model=List[SampleSchema])
|
||||
def get_samples_in_shipment(shipment_id: str, db: Session = Depends(get_db)):
|
||||
shipment = db.query(ShipmentModel).filter(ShipmentModel.shipment_id == shipment_id).first()
|
||||
def get_samples_in_shipment(id: int, db: Session = Depends(get_db)):
|
||||
shipment = db.query(ShipmentModel).filter(ShipmentModel.id == id).first()
|
||||
if shipment is None:
|
||||
raise HTTPException(status_code=404, detail="Shipment not found")
|
||||
|
||||
@ -175,12 +179,16 @@ def get_samples_in_shipment(shipment_id: str, db: Session = Depends(get_db)):
|
||||
return samples
|
||||
|
||||
@router.get("/{shipment_id}/dewars/{dewar_id}/samples", response_model=List[SampleSchema])
|
||||
def get_samples_in_dewar(shipment_id: str, dewar_id: str, db: Session = Depends(get_db)):
|
||||
shipment = db.query(ShipmentModel).filter(ShipmentModel.shipment_id == shipment_id).first()
|
||||
def get_samples_in_dewar(
|
||||
shipment_id: int, dewar_id: int, db: Session = Depends(get_db)
|
||||
):
|
||||
shipment = db.query(ShipmentModel).filter(ShipmentModel.id == shipment_id).first()
|
||||
if shipment is None:
|
||||
raise HTTPException(status_code=404, detail="Shipment not found")
|
||||
|
||||
dewar = db.query(DewarModel).filter(DewarModel.id == dewar_id, DewarModel.shipment_id == shipment_id).first()
|
||||
dewar = db.query(DewarModel).filter(
|
||||
DewarModel.id == dewar_id, DewarModel.shipment_id == shipment_id
|
||||
).first()
|
||||
if dewar is None:
|
||||
raise HTTPException(status_code=404, detail="Dewar not found in shipment")
|
||||
|
||||
@ -192,8 +200,8 @@ def get_samples_in_dewar(shipment_id: str, dewar_id: str, db: Session = Depends(
|
||||
|
||||
|
||||
@router.put("/{shipment_id}/comments", response_model=ShipmentSchema)
|
||||
async def update_shipment_comments(shipment_id: str, comments_data: UpdateShipmentComments, db: Session = Depends(get_db)):
|
||||
shipment = db.query(ShipmentModel).filter(ShipmentModel.shipment_id == shipment_id).first()
|
||||
async def update_shipment_comments(id: int, comments_data: UpdateShipmentComments, db: Session = Depends(get_db)):
|
||||
shipment = db.query(ShipmentModel).filter(ShipmentModel.id == id).first()
|
||||
if not shipment:
|
||||
raise HTTPException(status_code=404, detail="Shipment not found")
|
||||
|
||||
|
@ -104,8 +104,8 @@ class DewarCreate(DewarBase):
|
||||
|
||||
|
||||
class Dewar(DewarBase):
|
||||
id: str
|
||||
shipment_id: Optional[str]
|
||||
id: int
|
||||
shipment_id: Optional[int]
|
||||
contact_person: Optional[ContactPerson]
|
||||
return_address: Optional[Address]
|
||||
pucks: Optional[List[Puck]] = []
|
||||
@ -138,7 +138,7 @@ class Proposal(BaseModel):
|
||||
|
||||
# Shipment schemas
|
||||
class Shipment(BaseModel):
|
||||
shipment_id: int
|
||||
id: int
|
||||
shipment_name: str
|
||||
shipment_date: date
|
||||
shipment_status: str
|
||||
@ -156,7 +156,7 @@ class ShipmentCreate(BaseModel):
|
||||
shipment_name: str
|
||||
shipment_date: date
|
||||
shipment_status: str
|
||||
comments: Optional[constr(max_length=500)]
|
||||
comments: Optional[constr(max_length=200)]
|
||||
contact_person_id: int
|
||||
return_address_id: int
|
||||
proposal_id: int
|
||||
|
@ -79,7 +79,7 @@ const ShipmentDetails: React.FC<ShipmentDetailsProps> = ({
|
||||
const confirmed = window.confirm('Are you sure you want to delete this dewar?');
|
||||
if (confirmed && selectedShipment) {
|
||||
try {
|
||||
const updatedShipment = await ShipmentsService.removeDewarFromShipmentShipmentsShipmentIdRemoveDewarDewarIdDelete(selectedShipment.shipment_id, dewarId);
|
||||
const updatedShipment = await ShipmentsService.removeDewarFromShipmentShipmentsShipmentIdRemoveDewarDewarIdDelete(selectedShipment.id, dewarId);
|
||||
setSelectedShipment(updatedShipment);
|
||||
setLocalSelectedDewar(null);
|
||||
refreshShipments();
|
||||
@ -116,7 +116,7 @@ const ShipmentDetails: React.FC<ShipmentDetailsProps> = ({
|
||||
const createdDewar = await DewarsService.createDewarDewarsPost(newDewarToPost);
|
||||
|
||||
if (createdDewar && selectedShipment) {
|
||||
const updatedShipment = await ShipmentsService.addDewarToShipmentShipmentsShipmentIdAddDewarPost(selectedShipment.shipment_id, createdDewar.id);
|
||||
const updatedShipment = await ShipmentsService.addDewarToShipmentShipmentsShipmentIdAddDewarPost(selectedShipment.id, createdDewar.id);
|
||||
setSelectedShipment(updatedShipment);
|
||||
setIsAddingDewar(false);
|
||||
setNewDewar(initialNewDewarState);
|
||||
@ -137,12 +137,12 @@ const ShipmentDetails: React.FC<ShipmentDetailsProps> = ({
|
||||
};
|
||||
|
||||
const handleSaveComments = async () => {
|
||||
if (selectedShipment && selectedShipment.shipment_id) {
|
||||
if (selectedShipment && selectedShipment.id) {
|
||||
try {
|
||||
const payload = { comments };
|
||||
|
||||
// Assuming `updateShipmentCommentsShipmentsShipmentIdCommentsPut` only needs the shipment ID
|
||||
const updatedShipment = await ShipmentsService.updateShipmentCommentsShipmentsShipmentIdCommentsPut(selectedShipment.shipment_id, payload);
|
||||
const updatedShipment = await ShipmentsService.updateShipmentCommentsShipmentsShipmentIdCommentsPut(selectedShipment.id, payload);
|
||||
|
||||
setSelectedShipment({ ...selectedShipment, comments: updatedShipment.comments });
|
||||
setInitialComments(comments);
|
||||
@ -344,7 +344,7 @@ const ShipmentDetails: React.FC<ShipmentDetailsProps> = ({
|
||||
initialReturnAddresses={localSelectedDewar?.return_address ? [localSelectedDewar.return_address] : []} // Focus on dewar return address
|
||||
defaultContactPerson={localSelectedDewar?.contact_person}
|
||||
defaultReturnAddress={localSelectedDewar?.return_address}
|
||||
shipmentId={selectedShipment?.shipment_id || ''}
|
||||
shipmentId={selectedShipment?.id || ''}
|
||||
refreshShipments={refreshShipments}
|
||||
/>
|
||||
</Box>
|
||||
|
@ -41,7 +41,7 @@ const ShipmentPanel: React.FC<ShipmentPanelProps> = ({
|
||||
if (selectedShipment) {
|
||||
const confirmed = window.confirm(`Are you sure you want to delete the shipment: ${selectedShipment.shipment_name}?`);
|
||||
if (confirmed) {
|
||||
await deleteShipment(selectedShipment.shipment_id);
|
||||
await deleteShipment(selectedShipment.id);
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -58,7 +58,7 @@ const ShipmentPanel: React.FC<ShipmentPanelProps> = ({
|
||||
};
|
||||
|
||||
const handleShipmentSelection = (shipment: ShipmentsService) => {
|
||||
const isSelected = selectedShipment?.shipment_id === shipment.shipment_id;
|
||||
const isSelected = selectedShipment?.id === shipment.id;
|
||||
const updatedShipment = isSelected ? null : shipment;
|
||||
console.log("Shipment selected:", updatedShipment); // debug log
|
||||
selectShipment(updatedShipment);
|
||||
@ -102,7 +102,7 @@ const ShipmentPanel: React.FC<ShipmentPanelProps> = ({
|
||||
</Box>
|
||||
{shipments.map((shipment) => (
|
||||
<Button
|
||||
key={shipment.shipment_id}
|
||||
key={shipment.id}
|
||||
onClick={() => handleShipmentSelection(shipment)}
|
||||
sx={{
|
||||
width: '100%',
|
||||
@ -117,12 +117,12 @@ const ShipmentPanel: React.FC<ShipmentPanelProps> = ({
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'space-between',
|
||||
backgroundColor: selectedShipment?.shipment_id === shipment.shipment_id ? '#52893e' : '#424242',
|
||||
backgroundColor: selectedShipment?.id === shipment.id ? '#52893e' : '#424242',
|
||||
'&:hover': {
|
||||
backgroundColor: selectedShipment?.shipment_id === shipment.shipment_id ? '#9aca8c' : '#616161',
|
||||
backgroundColor: selectedShipment?.id === shipment.id ? '#9aca8c' : '#616161',
|
||||
},
|
||||
'&:active': {
|
||||
backgroundColor: selectedShipment?.shipment_id === shipment.shipment_id ? '#915151' : '#212121',
|
||||
backgroundColor: selectedShipment?.id === shipment.id ? '#915151' : '#212121',
|
||||
},
|
||||
}}
|
||||
>
|
||||
@ -160,7 +160,7 @@ const ShipmentPanel: React.FC<ShipmentPanelProps> = ({
|
||||
</Box>
|
||||
</Box>
|
||||
<Box sx={{ display: 'flex', alignItems: 'center' }}>
|
||||
{selectedShipment?.shipment_id === shipment.shipment_id && (
|
||||
{selectedShipment?.id === shipment.id && (
|
||||
<>
|
||||
<IconButton
|
||||
onClick={openUploadDialog}
|
||||
|
Loading…
x
Reference in New Issue
Block a user