80 lines
1.6 KiB
Python
80 lines
1.6 KiB
Python
"""Pydantic schemas for request/response validation."""
|
|||
|
|
|
||
|
|
from datetime import datetime
|
||
|
|
from pydantic import BaseModel
|
||
|
|
from typing import Optional
|
||
|
|
from enum import Enum
|
||
|
|
|
||
|
|
|
||
|
|
class EntryType(str, Enum):
|
||
|
|
"""Type of wallet entry."""
|
||
|
|
INCOME = "income"
|
||
|
|
EXPENSE = "expense"
|
||
|
|
|
||
|
|
|
||
|
|
class UserRegister(BaseModel):
|
||
|
|
"""Schema for user registration."""
|
||
|
|
username: str
|
||
|
|
email: str
|
||
|
|
password: str
|
||
|
|
|
||
|
|
|
||
|
|
class UserLogin(BaseModel):
|
||
|
|
"""Schema for user login."""
|
||
|
|
username: str
|
||
|
|
password: str
|
||
|
|
|
||
|
|
|
||
|
|
class UserResponse(BaseModel):
|
||
|
|
"""Schema for user response."""
|
||
|
|
id: int
|
||
|
|
username: str
|
||
|
|
email: str
|
||
|
|
created_at: datetime
|
||
|
|
|
||
|
|
class Config:
|
||
|
|
from_attributes = True
|
||
|
|
|
||
|
|
|
||
|
|
class WalletEntryCreate(BaseModel):
|
||
|
|
"""Schema for creating a wallet entry."""
|
||
|
|
amount: float
|
||
|
|
entry_type: EntryType
|
||
|
|
description: str
|
||
|
|
|
||
|
|
|
||
|
|
class WalletEntryUpdate(BaseModel):
|
||
|
|
"""Schema for updating a wallet entry."""
|
||
|
|
amount: Optional[float] = None
|
||
|
|
entry_type: Optional[EntryType] = None
|
||
|
|
description: Optional[str] = None
|
||
|
|
|
||
|
|
|
||
|
|
class WalletEntryResponse(BaseModel):
|
||
|
|
"""Schema for wallet entry response."""
|
||
|
|
id: int
|
||
|
|
user_id: int
|
||
|
|
amount: float
|
||
|
|
entry_type: EntryType
|
||
|
|
description: str
|
||
|
|
created_at: datetime
|
||
|
|
updated_at: datetime
|
||
|
|
|
||
|
|
class Config:
|
||
|
|
from_attributes = True
|
||
|
|
|
||
|
|
|
||
|
|
class DashboardMetrics(BaseModel):
|
||
|
|
"""Schema for dashboard metrics."""
|
||
|
|
total_balance: float
|
||
|
|
total_income: float
|
||
|
|
total_expenses: float
|
||
|
|
entry_count: int
|
||
|
|
|
||
|
|
|
||
|
|
class TokenResponse(BaseModel):
|
||
|
|
"""Schema for token response."""
|
||
|
|
access_token: str
|
||
|
|
token_type: str
|
||
|
|
user: UserResponse
|