After Graduate Update
This commit is contained in:
parent
b92a91ab37
commit
c6917dd85e
69 changed files with 7540 additions and 0 deletions
75
ressult/app/models/__init__.py
Normal file
75
ressult/app/models/__init__.py
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
# 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue