Add POST endpoint for products
This commit is contained in:
parent
34f35e5db1
commit
f5969c704e
16
endpoints/products.post.py
Normal file
16
endpoints/products.post.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
from fastapi import APIRouter, Depends, HTTPException, status
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
from core.database import get_db
|
||||||
|
from models.product import Product
|
||||||
|
from schemas.product import ProductSchema, ProductCreate
|
||||||
|
from helpers.product_helpers import create_product
|
||||||
|
|
||||||
|
router = APIRouter()
|
||||||
|
|
||||||
|
@router.post("/products", status_code=201, response_model=ProductSchema)
|
||||||
|
async def add_product(
|
||||||
|
product: ProductCreate,
|
||||||
|
db: Session = Depends(get_db)
|
||||||
|
):
|
||||||
|
"""Create a new product"""
|
||||||
|
return create_product(db=db, product=product)
|
Loading…
x
Reference in New Issue
Block a user