1
from typing import Optional, List
3
from fastapi_filter.contrib.sqlalchemy import Filter
4
from pydantic import BaseModel, Field, field_validator
5
from pydantic.types import UUID
7
from app.basic.store.models.store_models import Store
8
from app.basic.store.models.store_models import StoreType
9
from core.schemas import BaseFilter
10
from core.schemas.basic_schemes import BasicModel
11
from core.schemas.list_schema import GenericListSchema
12
from core.schemas.timestamps import TimeStampScheme
15
class StoreBaseScheme(BasicModel):
16
vars: Optional[dict] = None
17
title: str = Field(title='Title', table=True, form=True)
18
external_number: Optional[str] = Field(default=None, title='External ID', table=True, form=True)
19
address: str = Field(title='Address', table=True, form=True)
20
source: Optional[StoreType] = Field(default=StoreType.INTERNAL, title='Source', table=True, form=True)
25
from_attributes = True
27
service = 'app.basic.store.services.StoreService'
29
@field_validator('vars', mode='before')
31
def convert_int_serial(cls, v):
34
class StoreUpdateScheme(StoreBaseScheme):
35
title: str = Field(title='Title', table=True, form=True)
36
source: Optional[StoreType] = Field(default=None, title='Source', table=True, form=True)
39
class StoreCreateScheme(StoreBaseScheme):
43
class StoreScheme(StoreCreateScheme, TimeStampScheme):
44
company_id: UUID = Field(title='Company ID', model='company')
50
class StoreFilter(BaseFilter):
51
title__ilike: Optional[str] = Field(default=None, title='Title')
52
address__ilike: Optional[str] = Field(description="address", default=None, title='Address')
53
source__in: Optional[list[StoreType]] = Field(default=None, title='Source')
56
populate_by_name = True
58
class Constants(Filter.Constants):
60
ordering_field_name = "order_by"
61
search_field_name = "search"
62
search_model_fields = ["title", "external_number", "address"]
65
class StoreListSchema(GenericListSchema):
66
data: Optional[List[StoreScheme]]