From 5f6918db393ed78dd8f038e9e5f1ea85f811dc52 Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 16 Jul 2026 15:16:23 +0200 Subject: added get for orders query --- order-service/app/api/v1/endpoints/orders.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'order-service/app/api/v1/endpoints') 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.", ) + + +@router.get("/", 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.", + ) -- cgit v1.2.3