crappy
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from schemas.base import CustomModel
|
||||
from schemas.base import CustomModelCamel, CustomModelSnake
|
||||
|
||||
|
||||
class AuthLoginRequest(CustomModel):
|
||||
class AuthLoginRequest(CustomModelSnake):
|
||||
auth_date: int
|
||||
first_name: str
|
||||
hash: str
|
||||
@@ -9,5 +9,5 @@ class AuthLoginRequest(CustomModel):
|
||||
photo_url: str
|
||||
|
||||
|
||||
class AuthLoginResponse(CustomModel):
|
||||
class AuthLoginResponse(CustomModelCamel):
|
||||
access_token: str
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from pydantic import BaseModel
|
||||
from pydantic.alias_generators import to_camel
|
||||
|
||||
|
||||
class CustomConfig:
|
||||
@@ -6,21 +7,34 @@ class CustomConfig:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class CustomModel(BaseModel):
|
||||
class CustomModelCamel(BaseModel):
|
||||
class Config:
|
||||
from_attributes = True
|
||||
alias_generator = to_camel
|
||||
populate_by_name = True
|
||||
|
||||
@classmethod
|
||||
def from_sql_model(cls, model, fields: dict):
|
||||
model_dict = {c.name: getattr(model, c.name) for c in model.__table__.columns}
|
||||
model_dict.update(fields)
|
||||
return cls(**model_dict)
|
||||
|
||||
|
||||
class CustomModelSnake(BaseModel):
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class OkMessageSchema(BaseModel):
|
||||
class OkMessageSchema(CustomModelCamel):
|
||||
ok: bool
|
||||
message: str
|
||||
|
||||
|
||||
class PaginationSchema(CustomModel):
|
||||
class PaginationSchema(CustomModelCamel):
|
||||
page: int
|
||||
items_per_page: int
|
||||
|
||||
|
||||
class PaginationInfoSchema(CustomModel):
|
||||
class PaginationInfoSchema(CustomModelCamel):
|
||||
total_pages: int
|
||||
total_items: int
|
||||
|
||||
@@ -1,42 +1,42 @@
|
||||
from typing import List
|
||||
|
||||
from schemas.base import CustomModel
|
||||
from schemas.base import CustomModelCamel
|
||||
|
||||
|
||||
class ClientDetailsSchema(CustomModel):
|
||||
class ClientDetailsSchema(CustomModelCamel):
|
||||
address: str | None = None
|
||||
phone_number: str | None = None
|
||||
inn: int | None = None
|
||||
email: str | None = None
|
||||
|
||||
|
||||
class ClientSchema(CustomModel):
|
||||
class ClientSchema(CustomModelCamel):
|
||||
id: int
|
||||
name: str
|
||||
details: ClientDetailsSchema | None = None
|
||||
|
||||
|
||||
class ClientSearchRequest(CustomModel):
|
||||
class ClientSearchRequest(CustomModelCamel):
|
||||
name: str
|
||||
|
||||
|
||||
class ClientCreateRequest(CustomModel):
|
||||
class ClientCreateRequest(CustomModelCamel):
|
||||
name: str
|
||||
address: str
|
||||
|
||||
|
||||
class ClientSearchResponse(CustomModel):
|
||||
class ClientSearchResponse(CustomModelCamel):
|
||||
clients: List[ClientSchema]
|
||||
|
||||
|
||||
class ClientUpdateDetailsRequest(CustomModel):
|
||||
class ClientUpdateDetailsRequest(CustomModelCamel):
|
||||
client_id: int
|
||||
details: ClientDetailsSchema
|
||||
|
||||
|
||||
class ClientUpdateDetailsResponse(CustomModel):
|
||||
class ClientUpdateDetailsResponse(CustomModelCamel):
|
||||
ok: bool
|
||||
|
||||
|
||||
class ClientGetAllResponse(CustomModel):
|
||||
class ClientGetAllResponse(CustomModelCamel):
|
||||
clients: List[ClientSchema]
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
import datetime
|
||||
from typing import List
|
||||
|
||||
from schemas.base import CustomModel
|
||||
from schemas.base import CustomModelCamel
|
||||
from schemas.client import ClientSchema
|
||||
|
||||
|
||||
# region Entities
|
||||
class FastDeal(CustomModel):
|
||||
class FastDeal(CustomModelCamel):
|
||||
name: str
|
||||
client: ClientSchema
|
||||
comment: str
|
||||
acceptance_date: datetime.datetime
|
||||
|
||||
|
||||
class DealSummary(CustomModel):
|
||||
class DealSummary(CustomModelCamel):
|
||||
id: int
|
||||
name: str
|
||||
client_name: str
|
||||
@@ -22,7 +22,7 @@ class DealSummary(CustomModel):
|
||||
total_price: int
|
||||
|
||||
|
||||
class DealServiceSchema(CustomModel):
|
||||
class DealServiceSchema(CustomModelCamel):
|
||||
id: int
|
||||
quantity: int
|
||||
|
||||
@@ -30,16 +30,16 @@ class DealServiceSchema(CustomModel):
|
||||
# endregion Entities
|
||||
|
||||
# region Requests
|
||||
class DealChangeStatusRequest(CustomModel):
|
||||
class DealChangeStatusRequest(CustomModelCamel):
|
||||
deal_id: int
|
||||
new_status: int
|
||||
|
||||
|
||||
class DealCreateRequest(CustomModel):
|
||||
class DealCreateRequest(CustomModelCamel):
|
||||
name: str
|
||||
|
||||
|
||||
class DealQuickCreateRequest(CustomModel):
|
||||
class DealQuickCreateRequest(CustomModelCamel):
|
||||
name: str
|
||||
client_name: str
|
||||
client_address: str
|
||||
@@ -47,11 +47,11 @@ class DealQuickCreateRequest(CustomModel):
|
||||
acceptance_date: datetime.datetime
|
||||
|
||||
|
||||
class DealSummaryRequest(CustomModel):
|
||||
class DealSummaryRequest(CustomModelCamel):
|
||||
pass
|
||||
|
||||
|
||||
class DealAddServicesRequest(CustomModel):
|
||||
class DealAddServicesRequest(CustomModelCamel):
|
||||
deal_id: int
|
||||
services: list[DealServiceSchema]
|
||||
|
||||
@@ -60,23 +60,23 @@ class DealAddServicesRequest(CustomModel):
|
||||
|
||||
# region Responses
|
||||
|
||||
class DealChangeStatusResponse(CustomModel):
|
||||
class DealChangeStatusResponse(CustomModelCamel):
|
||||
ok: bool
|
||||
|
||||
|
||||
class DealCreateResponse(CustomModel):
|
||||
class DealCreateResponse(CustomModelCamel):
|
||||
ok: bool
|
||||
|
||||
|
||||
class DealQuickCreateResponse(CustomModel):
|
||||
class DealQuickCreateResponse(CustomModelCamel):
|
||||
deal_id: int
|
||||
|
||||
|
||||
class DealSummaryResponse(CustomModel):
|
||||
class DealSummaryResponse(CustomModelCamel):
|
||||
summaries: List[DealSummary]
|
||||
|
||||
|
||||
class DealAddServicesResponse(CustomModel):
|
||||
class DealAddServicesResponse(CustomModelCamel):
|
||||
ok: bool
|
||||
message: str
|
||||
# endregion Responses
|
||||
|
||||
@@ -1,33 +1,51 @@
|
||||
from typing import List
|
||||
|
||||
from schemas.base import CustomModel, PaginationInfoSchema
|
||||
from schemas.base import CustomModelCamel, PaginationInfoSchema, OkMessageSchema
|
||||
|
||||
|
||||
# region Entities
|
||||
class ProductSchema(CustomModel):
|
||||
class ProductSchema(CustomModelCamel):
|
||||
id: int
|
||||
name: str
|
||||
article: str
|
||||
client_id: int
|
||||
barcodes: list[str]
|
||||
|
||||
|
||||
# endregion
|
||||
|
||||
# region Requests
|
||||
class ProductCreateRequest(CustomModel):
|
||||
class ProductCreateRequest(CustomModelCamel):
|
||||
name: str
|
||||
article: str
|
||||
client_id: int
|
||||
barcodes: List[str]
|
||||
|
||||
|
||||
class ProductDeleteRequest(CustomModelCamel):
|
||||
product_id: int
|
||||
|
||||
|
||||
class ProductUpdateRequest(CustomModelCamel):
|
||||
product: ProductSchema
|
||||
|
||||
|
||||
# endregion
|
||||
|
||||
# region Responses
|
||||
class ProductCreateResponse(CustomModel):
|
||||
product_id: int
|
||||
class ProductCreateResponse(OkMessageSchema):
|
||||
product_id: int | None = None
|
||||
|
||||
|
||||
class ProductGetResponse(CustomModel):
|
||||
class ProductGetResponse(CustomModelCamel):
|
||||
products: List[ProductSchema]
|
||||
pagination_info: PaginationInfoSchema
|
||||
|
||||
|
||||
class ProductDeleteResponse(OkMessageSchema):
|
||||
pass
|
||||
|
||||
|
||||
class ProductUpdateResponse(OkMessageSchema):
|
||||
pass
|
||||
# endregion
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
from typing import List
|
||||
|
||||
from schemas.base import CustomModel, OkMessageSchema
|
||||
from schemas.base import CustomModelCamel, OkMessageSchema
|
||||
|
||||
|
||||
# region Entities
|
||||
class ServiceCategorySchema(CustomModel):
|
||||
class ServiceCategorySchema(CustomModelCamel):
|
||||
id: int
|
||||
name: str
|
||||
|
||||
|
||||
class ServiceSchema(CustomModel):
|
||||
class ServiceSchema(CustomModelCamel):
|
||||
id: int
|
||||
name: str
|
||||
category: ServiceCategorySchema
|
||||
@@ -20,11 +20,11 @@ class ServiceSchema(CustomModel):
|
||||
|
||||
|
||||
# region Requests
|
||||
class ServiceCreateRequest(CustomModel):
|
||||
class ServiceCreateRequest(CustomModelCamel):
|
||||
service: ServiceSchema
|
||||
|
||||
|
||||
class ServiceCreateCategoryRequest(CustomModel):
|
||||
class ServiceCreateCategoryRequest(CustomModelCamel):
|
||||
category: ServiceCategorySchema
|
||||
|
||||
|
||||
@@ -32,11 +32,11 @@ class ServiceCreateCategoryRequest(CustomModel):
|
||||
|
||||
|
||||
# region Responses
|
||||
class ServiceGetAllResponse(CustomModel):
|
||||
class ServiceGetAllResponse(CustomModelCamel):
|
||||
services: List[ServiceSchema]
|
||||
|
||||
|
||||
class ServiceGetAllCategoriesResponse(CustomModel):
|
||||
class ServiceGetAllCategoriesResponse(CustomModelCamel):
|
||||
categories: List[ServiceCategorySchema]
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user