Обновление приложения
This commit is contained in:
89
backend/app/schemas/operation.py
Normal file
89
backend/app/schemas/operation.py
Normal file
@@ -0,0 +1,89 @@
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
from pydantic import BaseModel, Field
|
||||
from app.schemas.currency import CurrencyOut
|
||||
from app.schemas.category import CategoryOut
|
||||
from app.schemas.location import LocationOut
|
||||
|
||||
|
||||
class OperationTypeOut(BaseModel):
|
||||
id: int
|
||||
name: str
|
||||
description: str | None = None
|
||||
|
||||
model_config = {"from_attributes": True}
|
||||
|
||||
|
||||
class OperationCreate(BaseModel):
|
||||
account_id: int
|
||||
category_id: int | None = None
|
||||
operation_type_id: int
|
||||
amount: Decimal = Field(..., gt=0)
|
||||
currency_id: int
|
||||
amount_converted: Decimal | None = None
|
||||
exchange_rate: Decimal | None = None
|
||||
date: datetime
|
||||
description: str | None = None
|
||||
location_id: int | None = None
|
||||
is_planned: bool = False
|
||||
|
||||
|
||||
class OperationUpdate(BaseModel):
|
||||
category_id: int | None = None
|
||||
amount: Decimal | None = Field(None, gt=0)
|
||||
date: datetime | None = None
|
||||
description: str | None = None
|
||||
location_id: int | None = None
|
||||
is_planned: bool | None = None
|
||||
|
||||
|
||||
class OperationOut(BaseModel):
|
||||
id: int
|
||||
user_id: int
|
||||
account_id: int
|
||||
category_id: int | None = None
|
||||
category: CategoryOut | None = None
|
||||
operation_type_id: int
|
||||
operation_type: OperationTypeOut
|
||||
amount: Decimal
|
||||
currency_id: int
|
||||
currency: CurrencyOut
|
||||
amount_converted: Decimal | None = None
|
||||
exchange_rate: Decimal | None = None
|
||||
date: datetime
|
||||
description: str | None = None
|
||||
location_id: int | None = None
|
||||
location: LocationOut | None = None
|
||||
is_planned: bool
|
||||
created_at: datetime
|
||||
|
||||
model_config = {"from_attributes": True}
|
||||
|
||||
|
||||
class OperationRelationCreate(BaseModel):
|
||||
operation_from_id: int
|
||||
operation_to_id: int
|
||||
relation_type: str = Field(..., pattern="^(transfer|split|correction)$")
|
||||
|
||||
|
||||
class OperationRelationOut(BaseModel):
|
||||
id: int
|
||||
operation_from_id: int
|
||||
operation_to_id: int
|
||||
relation_type: str
|
||||
created_at: datetime
|
||||
|
||||
model_config = {"from_attributes": True}
|
||||
|
||||
|
||||
class TransferCreate(BaseModel):
|
||||
"""Convenience schema: creates two linked operations in one request."""
|
||||
from_account_id: int
|
||||
to_account_id: int
|
||||
amount: Decimal = Field(..., gt=0)
|
||||
currency_id: int
|
||||
amount_converted: Decimal | None = None
|
||||
exchange_rate: Decimal | None = None
|
||||
date: datetime
|
||||
description: str | None = None
|
||||
location_id: int | None = None
|
||||
Reference in New Issue
Block a user