Connected frontend new contact, new address and shipments to backend
This commit is contained in:
@@ -4,6 +4,8 @@ from fastapi import HTTPException, status
|
||||
from pydantic import BaseModel
|
||||
from typing import List, Optional
|
||||
import logging
|
||||
import uuid
|
||||
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
@@ -53,7 +55,7 @@ class Dewar(BaseModel):
|
||||
|
||||
|
||||
class Shipment(BaseModel):
|
||||
shipment_id: str
|
||||
shipment_id: Optional[str] = None
|
||||
shipment_name: str
|
||||
shipment_date: str
|
||||
shipment_status: str
|
||||
@@ -233,16 +235,14 @@ async def get_shipment_contact_persons():
|
||||
return [{"shipment_id": shipment.shipment_id, "contact_person": shipment.get_shipment_contact_persons()} for shipment in
|
||||
shipments]
|
||||
|
||||
# Creation of a new shipment
|
||||
|
||||
@app.post("/shipments", response_model=Shipment, status_code=status.HTTP_201_CREATED)
|
||||
async def create_shipment(shipment: Shipment):
|
||||
# Check for duplicate shipment_id
|
||||
if any(s.shipment_id == shipment.shipment_id for s in shipments):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail="Shipment with this ID already exists."
|
||||
)
|
||||
# Automatically generate a shipment ID
|
||||
shipment_id = f'SHIP-{uuid.uuid4().hex[:8].upper()}' # Generates a unique shipment ID
|
||||
shipment.shipment_id = shipment_id # Set the generated ID
|
||||
|
||||
# Append the shipment to the list
|
||||
shipments.append(shipment)
|
||||
return shipment
|
||||
|
||||
|
||||
Reference in New Issue
Block a user