98 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			98 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
from typing import List
 | 
						|
from schemas.barcode import BarcodeTemplateSchema
 | 
						|
from schemas.base import CustomModelCamel, PaginationInfoSchema, OkMessageSchema
 | 
						|
from pydantic import field_validator
 | 
						|
from models import ProductBarcode
 | 
						|
 | 
						|
 | 
						|
# region Entities
 | 
						|
class BaseProductSchema(CustomModelCamel):
 | 
						|
    name: str
 | 
						|
    article: str | None = ''
 | 
						|
    client_id: int
 | 
						|
    barcodes: list[str]
 | 
						|
    barcode_template: BarcodeTemplateSchema | None = None
 | 
						|
 | 
						|
    # Attributes
 | 
						|
    brand: str | None = None
 | 
						|
    color: str | None = None
 | 
						|
    composition: str | None = None
 | 
						|
    size: str | None = None
 | 
						|
    additional_info: str | None = None
 | 
						|
 | 
						|
    @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
 | 
						|
 | 
						|
 | 
						|
class ProductSchema(BaseProductSchema):
 | 
						|
    id: int
 | 
						|
 | 
						|
 | 
						|
# endregion
 | 
						|
 | 
						|
# region Requests
 | 
						|
class ProductCreateRequest(BaseProductSchema):
 | 
						|
    pass
 | 
						|
 | 
						|
 | 
						|
class ProductDeleteRequest(CustomModelCamel):
 | 
						|
    product_id: int
 | 
						|
 | 
						|
 | 
						|
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
 | 
						|
class ProductCreateResponse(OkMessageSchema):
 | 
						|
    product_id: int | None = None
 | 
						|
 | 
						|
 | 
						|
class ProductGetResponse(CustomModelCamel):
 | 
						|
    products: List[ProductSchema]
 | 
						|
    pagination_info: PaginationInfoSchema
 | 
						|
 | 
						|
 | 
						|
class ProductDeleteResponse(OkMessageSchema):
 | 
						|
    pass
 | 
						|
 | 
						|
 | 
						|
class ProductUpdateResponse(OkMessageSchema):
 | 
						|
    pass
 | 
						|
 | 
						|
 | 
						|
class ProductAddBarcodeResponse(OkMessageSchema):
 | 
						|
    pass
 | 
						|
 | 
						|
 | 
						|
class ProductDeleteBarcodeResponse(OkMessageSchema):
 | 
						|
    pass
 | 
						|
 | 
						|
 | 
						|
class ProductGenerateBarcodeResponse(OkMessageSchema):
 | 
						|
    barcode: str
 | 
						|
 | 
						|
 | 
						|
class ProductExistsBarcodeResponse(CustomModelCamel):
 | 
						|
    exists: bool
 | 
						|
# endregion
 |