This commit is contained in:
2024-04-12 07:34:21 +03:00
parent 5c81af05d5
commit be623a3555
12 changed files with 513 additions and 93 deletions

View File

@@ -1,19 +1,25 @@
from typing import List
from pydantic import validator, field_validator
from models import ProductBarcode
from schemas.base import CustomModelCamel, PaginationInfoSchema, OkMessageSchema
# region Entities
class ProductBarcodeSchema(CustomModelCamel):
barcode: str
class ProductSchema(CustomModelCamel):
id: int
name: str
article: str
client_id: int
barcodes: list[ProductBarcodeSchema]
barcodes: list[str]
@field_validator('barcodes', mode="before")
def barcodes_to_list(cls, v):
if isinstance(v, list) and all([type(barcode) is ProductBarcode for barcode in v]):
return [barcode.barcode for barcode in v]
return v
# endregion
@@ -34,6 +40,20 @@ class ProductUpdateRequest(CustomModelCamel):
product: ProductSchema
class ProductAddBarcodeRequest(CustomModelCamel):
product_id: int
barcode: str
class ProductDeleteBarcodeRequest(CustomModelCamel):
product_id: int
barcode: str
class ProductGenerateBarcodeRequest(CustomModelCamel):
product_id: int
# endregion
# region Responses
@@ -52,4 +72,20 @@ class ProductDeleteResponse(OkMessageSchema):
class ProductUpdateResponse(OkMessageSchema):
pass
class ProductAddBarcodeResponse(OkMessageSchema):
pass
class ProductDeleteBarcodeResponse(OkMessageSchema):
pass
class ProductGenerateBarcodeResponse(OkMessageSchema):
barcode: str
class ProductExistsBarcodeResponse(CustomModelCamel):
exists: bool
# endregion