crappy
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user