95 lines
2.0 KiB
Python
95 lines
2.0 KiB
Python
from typing import Optional
|
|
|
|
from pydantic import field_validator
|
|
|
|
from modules.fulfillment_base.models import ProductBarcode
|
|
from modules.fulfillment_base.schemas.barcode_template import BarcodeTemplateSchema
|
|
from schemas.base import BaseSchema, BaseResponse, PaginationInfoSchema
|
|
|
|
|
|
# region Entity
|
|
|
|
|
|
class ProductImageSchema(BaseSchema):
|
|
id: int
|
|
product_id: int
|
|
image_url: str
|
|
|
|
|
|
class CreateProductSchema(BaseSchema):
|
|
name: str
|
|
article: str
|
|
factory_article: str
|
|
client_id: int
|
|
barcode_template_id: int
|
|
brand: Optional[str]
|
|
color: Optional[str]
|
|
composition: Optional[str]
|
|
size: Optional[str]
|
|
additional_info: Optional[str]
|
|
barcodes: list[str]
|
|
|
|
|
|
class ProductSchema(CreateProductSchema):
|
|
id: int
|
|
barcode_template: BarcodeTemplateSchema
|
|
|
|
@field_validator("barcodes", mode="before")
|
|
def barcodes_to_list(cls, v: Optional[list[ProductBarcode]]):
|
|
if isinstance(v, list):
|
|
return [barcode.barcode for barcode in v]
|
|
return v
|
|
|
|
|
|
class UpdateProductSchema(BaseSchema):
|
|
name: Optional[str] = None
|
|
article: Optional[str] = None
|
|
factory_article: Optional[str] = None
|
|
barcode_template_id: Optional[int] = None
|
|
brand: Optional[str] = None
|
|
color: Optional[str] = None
|
|
composition: Optional[str] = None
|
|
size: Optional[str] = None
|
|
additional_info: Optional[str] = None
|
|
barcodes: Optional[list[str]] = None
|
|
|
|
images: list[ProductImageSchema] | None = []
|
|
|
|
|
|
# endregion
|
|
|
|
# region Request
|
|
|
|
|
|
class CreateProductRequest(BaseSchema):
|
|
entity: CreateProductSchema
|
|
|
|
|
|
class UpdateProductRequest(BaseSchema):
|
|
entity: UpdateProductSchema
|
|
|
|
|
|
# endregion
|
|
|
|
# region Response
|
|
|
|
|
|
class GetProductsResponse(BaseSchema):
|
|
items: list[ProductSchema]
|
|
pagination_info: PaginationInfoSchema
|
|
|
|
|
|
class CreateProductResponse(BaseResponse):
|
|
entity: ProductSchema
|
|
|
|
|
|
class UpdateProductResponse(BaseResponse):
|
|
pass
|
|
|
|
|
|
class DeleteProductResponse(BaseResponse):
|
|
pass
|
|
|
|
|
|
# endregion
|