114 lines
3.0 KiB
Python
114 lines
3.0 KiB
Python
from typing import Annotated
|
|
|
|
from fastapi import APIRouter, Path, Query, File, UploadFile
|
|
|
|
from backend.dependecies import SessionDependency, PaginationDependency
|
|
from modules.fulfillment_base.schemas.product import *
|
|
from modules.fulfillment_base.services import ProductService, BarcodePrinterService
|
|
|
|
router = APIRouter(tags=["product"])
|
|
|
|
|
|
@router.get(
|
|
"/",
|
|
response_model=GetProductsResponse,
|
|
operation_id="get_products",
|
|
)
|
|
async def get_products(
|
|
session: SessionDependency,
|
|
pagination: PaginationDependency,
|
|
client_id: Optional[int] = Query(alias="clientId", default=None),
|
|
search_input: Optional[str] = Query(alias="searchInput", default=None),
|
|
):
|
|
return await ProductService(session).get_all(pagination, client_id, search_input)
|
|
|
|
|
|
@router.post(
|
|
"/",
|
|
response_model=CreateProductResponse,
|
|
operation_id="create_product",
|
|
)
|
|
async def create_product(
|
|
session: SessionDependency,
|
|
request: CreateProductRequest,
|
|
):
|
|
return await ProductService(session).create(request)
|
|
|
|
|
|
@router.patch(
|
|
"/{pk}",
|
|
response_model=UpdateProductResponse,
|
|
operation_id="update_product",
|
|
)
|
|
async def update_product(
|
|
session: SessionDependency,
|
|
request: UpdateProductRequest,
|
|
pk: int = Path(),
|
|
):
|
|
return await ProductService(session).update(pk, request)
|
|
|
|
|
|
@router.post(
|
|
"{pk}/images/upload",
|
|
response_model=ProductUploadImageResponse,
|
|
operation_id="upload_product_image",
|
|
)
|
|
async def upload_product_image(
|
|
session: SessionDependency,
|
|
upload_file: Annotated[UploadFile, File()],
|
|
pk: int = Path(),
|
|
):
|
|
return await ProductService(session).upload_image(pk, upload_file)
|
|
|
|
|
|
@router.delete(
|
|
"/{pk}",
|
|
response_model=DeleteProductResponse,
|
|
operation_id="delete_product",
|
|
)
|
|
async def delete_product(
|
|
session: SessionDependency,
|
|
pk: int = Path(),
|
|
):
|
|
return await ProductService(session).delete(pk)
|
|
|
|
|
|
@router.post(
|
|
"/barcode/get-pdf",
|
|
operation_id="get_product_barcode_pdf",
|
|
response_model=GetProductBarcodePdfResponse,
|
|
)
|
|
async def get_product_barcode_pdf(
|
|
request: GetProductBarcodePdfRequest, session: SessionDependency
|
|
):
|
|
service = BarcodePrinterService(session)
|
|
filename, base64_string = await service.generate_base64(request)
|
|
return GetProductBarcodePdfResponse(
|
|
base64_string=base64_string, filename=filename, mime_type="application/pdf"
|
|
)
|
|
|
|
|
|
@router.post(
|
|
"{pk}/barcode/image/upload",
|
|
response_model=BarcodeUploadImageResponse,
|
|
operation_id="upload_product_barcode_image",
|
|
)
|
|
async def upload_product_barcode_image(
|
|
upload_file: UploadFile,
|
|
session: SessionDependency,
|
|
pk: int,
|
|
):
|
|
return await ProductService(session).upload_barcode_image(pk, upload_file)
|
|
|
|
|
|
@router.delete(
|
|
"{pk}/barcode/image",
|
|
response_model=DeleteBarcodeImageResponse,
|
|
operation_id="delete_product_barcode_image",
|
|
)
|
|
async def delete_product_barcode_image(
|
|
session: SessionDependency,
|
|
pk: int,
|
|
):
|
|
return await ProductService(session).delete_barcode_image(pk)
|