Skip to content

Commit

Permalink
Basic /prices GET path
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Nov 14, 2023
1 parent 118a132 commit f6ae9aa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions app/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f6ae9aa

Please sign in to comment.