Esempio n. 1
0
async def create_product(
    new_product: ProductCreateUpdate,
    products_repo: ProductsRepository = Depends(
        get_repository(ProductsRepository)),
):
    created_product = await products_repo.create_product(
        new_product=new_product)
    return created_product
Esempio n. 2
0
async def get_order_by_id(
    order_id: PositiveInt,
    orders_repo: OrdersRepository = Depends(get_repository(OrdersRepository)),
):
    order = await orders_repo.get_order_by_id(order_id=order_id)
    if order is None:
        raise HTTPException(status.HTTP_404_NOT_FOUND, "Order not found")
    return order
Esempio n. 3
0
async def create_order_item(
    order_id: PositiveInt,
    new_order_item: OrderItemCreateUpdate,
    orders_repo: OrdersRepository = Depends(get_repository(OrdersRepository)),
):
    created_order = await orders_repo.create_order_item(
        order_id=order_id, new_order_item=new_order_item)
    return created_order
Esempio n. 4
0
async def get_product_by_id(
    product_id: PositiveInt,
    products_repo: ProductsRepository = Depends(
        get_repository(ProductsRepository)),
):
    product = await products_repo.get_product_by_id(product_id=product_id)
    if product is None:
        raise HTTPException(status.HTTP_404_NOT_FOUND, "Product not found")
    return product
Esempio n. 5
0
async def get_all_products(
    search: Optional[str] = None,
    pagination: Pagination = Depends(),
    products_repo: ProductsRepository = Depends(
        get_repository(ProductsRepository)),
):
    products = await products_repo.get_all_products(search=search,
                                                    pagination=pagination)
    return products
Esempio n. 6
0
async def full_update_order(
    order_update: OrderCreateUpdate,
    order_id: PositiveInt,
    orders_repo: OrdersRepository = Depends(get_repository(OrdersRepository)),
):
    updated_order = await orders_repo.update_order(order_id=order_id,
                                                   order_update=order_update,
                                                   patching=False)
    return updated_order
Esempio n. 7
0
async def get_all_order_items(
    order_id: PositiveInt,
    pagination: Pagination = Depends(),
    orders_repo: OrdersRepository = Depends(get_repository(OrdersRepository)),
):

    orders = await orders_repo.get_all_order_items(order_id=order_id,
                                                   pagination=pagination)
    return orders
Esempio n. 8
0
async def full_update_product(
    product_update: ProductCreateUpdate,
    product_id: PositiveInt,
    products_repo: ProductsRepository = Depends(
        get_repository(ProductsRepository)),
):
    updated_product = await products_repo.update_product(
        product_id=product_id, product_update=product_update, patching=False)
    if updated_product is None:
        raise HTTPException(status.HTTP_404_NOT_FOUND, "Product not found")
    return updated_product
Esempio n. 9
0
async def partial_update_product(
    product_update: ProductUpdate,
    product_id: PositiveInt,
    products_repo: ProductsRepository = Depends(
        get_repository(ProductsRepository)),
):
    if not product_update.dict(exclude_unset=True):
        raise HTTPException(status.HTTP_422_UNPROCESSABLE_ENTITY,
                            "empty payload")

    updated_product = await products_repo.update_product(
        product_id=product_id, product_update=product_update, patching=True)
    if updated_product is None:
        raise HTTPException(status.HTTP_404_NOT_FOUND, "Product not found")
    return updated_product
Esempio n. 10
0
async def partial_update_order(
    order_update: OrderUpdate,
    order_id: PositiveInt,
    orders_repo: OrdersRepository = Depends(get_repository(OrdersRepository)),
):
    # raise Exception(order_update.dict(exclude_unset=True))
    if not order_update.dict(exclude_unset=True):
        raise HTTPException(status.HTTP_422_UNPROCESSABLE_ENTITY,
                            "empty payload")

    updated_order = await orders_repo.update_order(order_id=order_id,
                                                   order_update=order_update,
                                                   patching=True)

    return updated_order
Esempio n. 11
0
async def create_order(
    new_order: OrderCreateUpdate,
    orders_repo: OrdersRepository = Depends(get_repository(OrdersRepository)),
):
    created_order = await orders_repo.create_order(new_order=new_order)
    return created_order
Esempio n. 12
0
async def get_all_orders(
    pagination: Pagination = Depends(),
    orders_repo: OrdersRepository = Depends(get_repository(OrdersRepository)),
):
    orders = await orders_repo.get_all_orders(pagination=pagination)
    return orders