This commit is contained in:
2024-04-12 07:34:21 +03:00
parent 5c81af05d5
commit be623a3555
12 changed files with 513 additions and 93 deletions

View File

@@ -1,5 +1,7 @@
from typing import List
from pydantic import validator, field_validator
from schemas.base import CustomModelCamel, OkMessageSchema
@@ -7,9 +9,13 @@ from schemas.base import CustomModelCamel, OkMessageSchema
class ClientDetailsSchema(CustomModelCamel):
address: str | None = None
phone_number: str | None = None
inn: int | None = None
inn: str | None = None
email: str | None = None
@field_validator("phone_number", "inn", "email", "address", mode="before")
def empty_string_to_none(cls, v):
return '' if v is None else v
class ClientSchema(CustomModelCamel):
id: int

View File

@@ -5,6 +5,7 @@ from schemas.base import CustomModelCamel, OkMessageSchema
from schemas.client import ClientSchema
from schemas.product import ProductSchema
from schemas.service import ServiceSchema
from schemas.user import UserSchema
# region Entities
@@ -34,6 +35,14 @@ class DealProductSchema(CustomModelCamel):
quantity: int
class DealStatusHistorySchema(CustomModelCamel):
user: UserSchema
changed_at: datetime.datetime
from_status: int
to_status: int
next_status_deadline: datetime.datetime
class DealSchema(CustomModelCamel):
id: int
name: str
@@ -42,7 +51,16 @@ class DealSchema(CustomModelCamel):
current_status: int
services: List[DealServiceSchema]
products: List[DealProductSchema]
# total_price: int
status_history: List[DealStatusHistorySchema]
is_deleted: bool
is_completed: bool
client: ClientSchema
class DealGeneralInfoSchema(CustomModelCamel):
name: str
is_deleted: bool
is_completed: bool
# endregion Entities
@@ -74,10 +92,6 @@ class DealAddServicesRequest(CustomModelCamel):
services: list[DealServiceSchema]
class DealGetAllResponse(CustomModelCamel):
deals: List[DealSchema]
class DealUpdateServiceQuantityRequest(CustomModelCamel):
deal_id: int
service_id: int
@@ -95,18 +109,52 @@ class DealDeleteServiceRequest(CustomModelCamel):
service_id: int
class DealDeleteServicesResponse(OkMessageSchema):
pass
class DealDeleteServicesRequest(CustomModelCamel):
deal_id: int
service_ids: List[int]
class DealUpdateProductQuantityRequest(CustomModelCamel):
deal_id: int
product_id: int
quantity: int
class DealAddProductRequest(CustomModelCamel):
deal_id: int
product_id: int
quantity: int
class DealDeleteProductRequest(CustomModelCamel):
deal_id: int
product_id: int
class DealDeleteProductsRequest(CustomModelCamel):
deal_id: int
product_ids: List[int]
class DealUpdateGeneralInfoRequest(CustomModelCamel):
deal_id: int
data: DealGeneralInfoSchema
# endregion Requests
# region Responses
class DealUpdateProductQuantityResponse(OkMessageSchema):
pass
class DealDeleteServicesResponse(OkMessageSchema):
pass
class DealGetAllResponse(CustomModelCamel):
deals: List[DealSchema]
class DealChangeStatusResponse(CustomModelCamel):
ok: bool
@@ -140,4 +188,20 @@ class DealAddServiceResponse(OkMessageSchema):
class DealDeleteServiceResponse(OkMessageSchema):
pass
class DealDeleteProductResponse(OkMessageSchema):
pass
class DealDeleteProductsResponse(OkMessageSchema):
pass
class DealAddProductResponse(OkMessageSchema):
pass
class DealUpdateGeneralInfoResponse(OkMessageSchema):
pass
# endregion Responses

View File

@@ -1,19 +1,25 @@
from typing import List
from pydantic import validator, field_validator
from models import ProductBarcode
from schemas.base import CustomModelCamel, PaginationInfoSchema, OkMessageSchema
# region Entities
class ProductBarcodeSchema(CustomModelCamel):
barcode: str
class ProductSchema(CustomModelCamel):
id: int
name: str
article: str
client_id: int
barcodes: list[ProductBarcodeSchema]
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
@@ -34,6 +40,20 @@ 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
@@ -52,4 +72,20 @@ class ProductDeleteResponse(OkMessageSchema):
class ProductUpdateResponse(OkMessageSchema):
pass
class ProductAddBarcodeResponse(OkMessageSchema):
pass
class ProductDeleteBarcodeResponse(OkMessageSchema):
pass
class ProductGenerateBarcodeResponse(OkMessageSchema):
barcode: str
class ProductExistsBarcodeResponse(CustomModelCamel):
exists: bool
# endregion

8
schemas/user.py Normal file
View File

@@ -0,0 +1,8 @@
from schemas.base import CustomModelCamel
class UserSchema(CustomModelCamel):
id: int
telegram_id: int
phone_number: str | None = None
is_admin: bool