From f6ae9aa6b906b54fe7cc1165884a7ea571bf04e1 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Tue, 14 Nov 2023 15:01:05 +0100 Subject: [PATCH] Basic /prices GET path --- app/api.py | 6 ++++++ app/crud.py | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/app/api.py b/app/api.py index 5098e7c9..1cc3f7ee 100644 --- a/app/api.py +++ b/app/api.py @@ -124,6 +124,12 @@ async def authentication(form_data: Annotated[OAuth2PasswordRequestForm, Depends raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail="Server error") +@app.get("/prices", response_model=list[schemas.PriceBase]) +async def get_price(): + db_prices = crud.get_prices(db) # type: ignore + return db_prices + + @app.post("/prices", response_model=schemas.PriceBase) async def create_price(price: schemas.PriceCreate, current_user: schemas.UserBase = Depends(get_current_user)): db_price = crud.create_price(db, price=price, user=current_user) # type: ignore diff --git a/app/crud.py b/app/crud.py index e1738bfd..6b579a28 100644 --- a/app/crud.py +++ b/app/crud.py @@ -49,6 +49,10 @@ def delete_user(db: Session, user_id: UserBase): return False +def get_prices(db: Session): + return db.query(Price).all() + + def create_price(db: Session, price: PriceCreate, user: UserBase): db_price = Price(**price.dict(), owner=user.user_id) db.add(db_price)