master-floor/ressult/app/models/__init__.py
2025-11-26 19:31:33 +03:00

75 lines
1.8 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# app/models/__init__.py
"""
Модели данных Pydantic для валидации API запросов и ответов
Соответствует ТЗ демонстрационного экзамена
"""
from pydantic import BaseModel, EmailStr, validator, conint
from typing import Optional
from decimal import Decimal
class PartnerBase(BaseModel):
partner_type: Optional[str] = None
company_name: str
legal_address: Optional[str] = None
inn: str
director_name: Optional[str] = None
phone: Optional[str] = None
email: Optional[EmailStr] = None
rating: conint(ge=0) # Рейтинг должен быть целым неотрицательным числом
sales_locations: Optional[str] = None
@validator('phone')
def validate_phone(cls, v):
if v and not v.startswith('+'):
raise ValueError('Телефон должен начинаться с +')
return v
class PartnerCreate(PartnerBase):
pass
class PartnerUpdate(PartnerBase):
pass
class Partner(PartnerBase):
partner_id: int
class Config:
from_attributes = True
class SaleBase(BaseModel):
partner_id: int
product_name: str
quantity: Decimal
sale_date: str
class SaleCreate(SaleBase):
pass
class Sale(SaleBase):
sale_id: int
class Config:
from_attributes = True
class UploadResponse(BaseModel):
message: str
processed_rows: int
errors: list[str] = []
class MaterialCalculationRequest(BaseModel):
product_type_id: int
material_type_id: int
quantity: conint(ge=1)
param1: float
param2: float
product_coeff: float
defect_percent: float
class MaterialCalculationResponse(BaseModel):
material_quantity: int
status: str
class DiscountResponse(BaseModel):
partner_id: int
total_sales: Decimal
discount_percent: int