feat: product endpoints changes for products table
This commit is contained in:
@ -1,6 +1,10 @@
|
||||
from typing import Optional
|
||||
|
||||
from schemas.base import BaseSchema, BaseResponse
|
||||
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
|
||||
@ -16,26 +20,38 @@ 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 = []
|
||||
|
||||
@ -60,6 +76,7 @@ class UpdateProductRequest(BaseSchema):
|
||||
|
||||
class GetProductsResponse(BaseSchema):
|
||||
items: list[ProductSchema]
|
||||
pagination_info: PaginationInfoSchema
|
||||
|
||||
|
||||
class CreateProductResponse(BaseResponse):
|
||||
|
||||
Reference in New Issue
Block a user