aboutsummaryrefslogtreecommitdiff
path: root/order-service/app/api/v1/endpoints/orders.py
diff options
context:
space:
mode:
Diffstat (limited to 'order-service/app/api/v1/endpoints/orders.py')
-rw-r--r--order-service/app/api/v1/endpoints/orders.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/order-service/app/api/v1/endpoints/orders.py b/order-service/app/api/v1/endpoints/orders.py
index beff480..934e7d5 100644
--- a/order-service/app/api/v1/endpoints/orders.py
+++ b/order-service/app/api/v1/endpoints/orders.py
@@ -1,6 +1,7 @@
from decimal import Decimal
from fastapi import APIRouter, Depends, HTTPException, status
from sqlalchemy.orm import Session
+from typing import List
from app.api import deps
from app.models.order import Order, OrderItem
@@ -73,3 +74,18 @@ def read_order(order_id: int, db: Session = Depends(deps.get_db)):
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail="Could not read the order.",
)
+
+
[email protected]("/", response_model=List[OrderOut])
+def list_orders(skip: int = 0, limit: int = 100, db: Session = Depends(deps.get_db)):
+ try:
+ orders = db.query(Order).offset(skip).limit(limit).all()
+ return orders
+
+ except Exception as e:
+ db.rollback()
+ print(e)
+ raise HTTPException(
+ status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ detail="Could not read the order.",
+ )