Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -71,6 +71,12 @@ class Order(Base):
|
|
| 71 |
payment_reference = Column(String(100), nullable=True)
|
| 72 |
last_location = Column(Text, nullable=True) # Stored as a JSON string
|
| 73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
class OrderTracking(Base):
|
| 75 |
__tablename__ = "order_tracking"
|
| 76 |
id = Column(Integer, primary_key=True, index=True)
|
|
@@ -80,6 +86,14 @@ class OrderTracking(Base):
|
|
| 80 |
timestamp = Column(DateTime, default=datetime.utcnow)
|
| 81 |
location = Column(Text, nullable=True) # Stored as a JSON string
|
| 82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
# --------------------
|
| 84 |
# INITIALIZATION
|
| 85 |
# --------------------
|
|
@@ -503,6 +517,29 @@ async def send_proactive_update(user_id: str, update_type: str):
|
|
| 503 |
|
| 504 |
return response
|
| 505 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 506 |
# --------------------
|
| 507 |
# ERROR HANDLING
|
| 508 |
# --------------------
|
|
|
|
| 71 |
payment_reference = Column(String(100), nullable=True)
|
| 72 |
last_location = Column(Text, nullable=True) # Stored as a JSON string
|
| 73 |
|
| 74 |
+
# New fields for delivery details:
|
| 75 |
+
package_description = Column(Text, nullable=False)
|
| 76 |
+
pickup_address = Column(Text, nullable=False)
|
| 77 |
+
delivery_address = Column(Text, nullable=False)
|
| 78 |
+
contact_number = Column(String(20), nullable=False)
|
| 79 |
+
|
| 80 |
class OrderTracking(Base):
|
| 81 |
__tablename__ = "order_tracking"
|
| 82 |
id = Column(Integer, primary_key=True, index=True)
|
|
|
|
| 86 |
timestamp = Column(DateTime, default=datetime.utcnow)
|
| 87 |
location = Column(Text, nullable=True) # Stored as a JSON string
|
| 88 |
|
| 89 |
+
|
| 90 |
+
class DeliveryOrderRequest(BaseModel):
|
| 91 |
+
user_id: str
|
| 92 |
+
package_description: str
|
| 93 |
+
pickup_address: str
|
| 94 |
+
delivery_address: str
|
| 95 |
+
contact_number: str
|
| 96 |
+
|
| 97 |
# --------------------
|
| 98 |
# INITIALIZATION
|
| 99 |
# --------------------
|
|
|
|
| 517 |
|
| 518 |
return response
|
| 519 |
|
| 520 |
+
@app.post("/delivery")
|
| 521 |
+
async def create_delivery_order(order_req: DeliveryOrderRequest):
|
| 522 |
+
async with async_session() as session:
|
| 523 |
+
try:
|
| 524 |
+
# Generate a unique order ID using UUID
|
| 525 |
+
order_id = str(uuid.uuid4())
|
| 526 |
+
new_order = Order(
|
| 527 |
+
order_id=order_id,
|
| 528 |
+
user_id=order_req.user_id,
|
| 529 |
+
status="pending",
|
| 530 |
+
package_description=order_req.package_description,
|
| 531 |
+
pickup_address=order_req.pickup_address,
|
| 532 |
+
delivery_address=order_req.delivery_address,
|
| 533 |
+
contact_number=order_req.contact_number,
|
| 534 |
+
)
|
| 535 |
+
session.add(new_order)
|
| 536 |
+
await session.commit()
|
| 537 |
+
await session.refresh(new_order)
|
| 538 |
+
return {"delivery_id": new_order.order_id}
|
| 539 |
+
except SQLAlchemyError as e:
|
| 540 |
+
await session.rollback()
|
| 541 |
+
raise HTTPException(status_code=500, detail="Error creating delivery order.") from e
|
| 542 |
+
|
| 543 |
# --------------------
|
| 544 |
# ERROR HANDLING
|
| 545 |
# --------------------
|