Separating Enums, Schemas and Models in account
This commit is contained in:
53
api/app/account/schemas.py
Normal file
53
api/app/account/schemas.py
Normal file
@@ -0,0 +1,53 @@
|
||||
from typing import Optional
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
from pydantic.json_schema import SkipJsonSchema
|
||||
from sqlmodel import Field, SQLModel
|
||||
from pydantic import Field as PydField
|
||||
|
||||
from account.enums import Asset, Liability, CategoryFamily
|
||||
|
||||
|
||||
class AccountBase(SQLModel):
|
||||
name: str = Field(index=True)
|
||||
parent_account_id: Optional[UUID] = Field(default=None, foreign_key="account.id")
|
||||
|
||||
class AccountBaseId(AccountBase):
|
||||
id: UUID | None = Field(default_factory=uuid4, primary_key=True)
|
||||
family: str = Field(index=True)
|
||||
type: str = Field(index=True)
|
||||
path: str = Field(index=True)
|
||||
|
||||
class AccountRead(AccountBaseId):
|
||||
pass
|
||||
|
||||
class BaseAccountWrite(AccountBase):
|
||||
path: SkipJsonSchema[str] = Field(default="")
|
||||
family: SkipJsonSchema[str] = Field(default="")
|
||||
|
||||
class AccountWrite(BaseAccountWrite):
|
||||
type: Asset | Liability = Field()
|
||||
parent_account_id: UUID | None = PydField(default=None, json_schema_extra={
|
||||
"foreign_key": {
|
||||
"reference": {
|
||||
"resource": "accounts",
|
||||
"schema": "AccountRead",
|
||||
"label": "name"
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
class AccountCreate(AccountWrite):
|
||||
pass
|
||||
|
||||
class AccountUpdate(AccountWrite):
|
||||
pass
|
||||
|
||||
class CategoryWrite(BaseAccountWrite):
|
||||
type: CategoryFamily = Field()
|
||||
|
||||
class CategoryCreate(CategoryWrite):
|
||||
pass
|
||||
|
||||
class CategoryUpdate(CategoryWrite):
|
||||
pass
|
||||
Reference in New Issue
Block a user