44 lines
1.1 KiB
Python
44 lines
1.1 KiB
Python
from datetime import datetime, date
|
|
from decimal import Decimal
|
|
from pydantic import BaseModel, Field
|
|
from app.schemas.category import CategoryOut
|
|
from app.schemas.currency import CurrencyOut
|
|
|
|
|
|
class BudgetCreate(BaseModel):
|
|
category_id: int
|
|
name: str = Field(..., max_length=200)
|
|
amount: Decimal = Field(..., gt=0)
|
|
currency_id: int
|
|
period_type: str = Field(..., pattern="^(monthly|weekly|yearly|custom)$")
|
|
start_date: date
|
|
end_date: date | None = None
|
|
is_active: bool = True
|
|
|
|
|
|
class BudgetUpdate(BaseModel):
|
|
name: str | None = None
|
|
amount: Decimal | None = Field(None, gt=0)
|
|
period_type: str | None = None
|
|
end_date: date | None = None
|
|
is_active: bool | None = None
|
|
|
|
|
|
class BudgetOut(BaseModel):
|
|
id: int
|
|
user_id: int
|
|
category_id: int
|
|
category: CategoryOut
|
|
name: str
|
|
amount: Decimal
|
|
currency_id: int
|
|
currency: CurrencyOut
|
|
period_type: str
|
|
start_date: date
|
|
end_date: date | None = None
|
|
is_active: bool
|
|
created_at: datetime
|
|
spent: Decimal | None = None # computed field
|
|
|
|
model_config = {"from_attributes": True}
|