92 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			92 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
from typing import List
 | 
						|
 | 
						|
from pydantic import validator, field_validator
 | 
						|
 | 
						|
from models import ProductBarcode
 | 
						|
from schemas.base import CustomModelCamel, PaginationInfoSchema, OkMessageSchema
 | 
						|
 | 
						|
 | 
						|
# region Entities
 | 
						|
 | 
						|
class ProductSchema(CustomModelCamel):
 | 
						|
    id: int
 | 
						|
    name: str
 | 
						|
    article: str
 | 
						|
    client_id: int
 | 
						|
    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
 | 
						|
 | 
						|
# region Requests
 | 
						|
class ProductCreateRequest(CustomModelCamel):
 | 
						|
    name: str
 | 
						|
    article: str
 | 
						|
    client_id: int
 | 
						|
    barcodes: List[str]
 | 
						|
 | 
						|
 | 
						|
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
 |