Add authentification

This commit is contained in:
2026-02-17 00:54:36 +01:00
parent ab98ba81c8
commit a8c8c489da
31 changed files with 1118 additions and 451 deletions

View File

@@ -9,6 +9,7 @@ router = APIRouter(prefix='/products')
#user=Depends(get_current_user)
@router.get('/', response_model=list[models.ProductPublic], )
def get_products(
user: models.User = Depends(get_current_user),
session: Session = Depends(get_session),
names: list[str] = Query([]),
types: list[str] = Query([]),
@@ -22,25 +23,41 @@ def get_products(
)
@router.get('/{id}', response_model=models.ProductPublic)
def get_product(id: int, session: Session = Depends(get_session)):
def get_product(
id: int,
user: models.User = Depends(get_current_user),
session: Session = Depends(get_session)
):
result = service.get_one(session, id)
if result is None:
raise HTTPException(status_code=404, detail=messages.notfound)
return result
@router.post('/', response_model=models.ProductPublic)
def create_product(product: models.ProductCreate, session: Session = Depends(get_session)):
def create_product(
product: models.ProductCreate,
user: models.User = Depends(get_current_user),
session: Session = Depends(get_session)
):
return service.create_one(session, product)
@router.put('/{id}', response_model=models.ProductPublic)
def update_product(id: int, product: models.ProductUpdate, session: Session = Depends(get_session)):
def update_product(
id: int, product: models.ProductUpdate,
user: models.User = Depends(get_current_user),
session: Session = Depends(get_session)
):
result = service.update_one(session, id, product)
if result is None:
raise HTTPException(status_code=404, detail=messages.notfound)
return result
@router.delete('/{id}', response_model=models.ProductPublic)
def delete_product(id: int, session: Session = Depends(get_session)):
def delete_product(
id: int,
user: models.User = Depends(get_current_user),
session: Session = Depends(get_session)
):
result = service.delete_one(session, id)
if result is None:
raise HTTPException(status_code=404, detail=messages.notfound)