File size: 753 Bytes
c169262
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from fastapi import APIRouter, status, HTTPException
from services.elasticsearch import get_order_details, get_customer

router = APIRouter()


@router.get("/track-order/{order_id}")
def handle_track_order(order_id: str):
    order = get_order_details(order_id)
    if not order:
        raise HTTPException(
            status_code=status.HTTP_404_NOT_FOUND, detail="Order not found")
    return order


@router.get("/order-history")
def view_order_history(customer_id: str):
    customer = get_customer(customer_id)
    if not customer:
        raise HTTPException(
            status_code=status.HTTP_404_NOT_FOUND, detail="Customer not found")
    # Retrieve order history from customer data
    return {"order_history": customer.get("orders", [])}