init commit
This commit is contained in:
27
app/schemas/__init__.py
Normal file
27
app/schemas/__init__.py
Normal file
@@ -0,0 +1,27 @@
|
||||
"""Pydantic schemas for request/response validation"""
|
||||
|
||||
from app.schemas.user import UserSchema, UserCreateSchema
|
||||
from app.schemas.family import FamilySchema, FamilyCreateSchema, FamilyMemberSchema
|
||||
from app.schemas.account import AccountSchema, AccountCreateSchema
|
||||
from app.schemas.category import CategorySchema, CategoryCreateSchema
|
||||
from app.schemas.transaction import TransactionSchema, TransactionCreateSchema
|
||||
from app.schemas.budget import BudgetSchema, BudgetCreateSchema
|
||||
from app.schemas.goal import GoalSchema, GoalCreateSchema
|
||||
|
||||
__all__ = [
|
||||
"UserSchema",
|
||||
"UserCreateSchema",
|
||||
"FamilySchema",
|
||||
"FamilyCreateSchema",
|
||||
"FamilyMemberSchema",
|
||||
"AccountSchema",
|
||||
"AccountCreateSchema",
|
||||
"CategorySchema",
|
||||
"CategoryCreateSchema",
|
||||
"TransactionSchema",
|
||||
"TransactionCreateSchema",
|
||||
"BudgetSchema",
|
||||
"BudgetCreateSchema",
|
||||
"GoalSchema",
|
||||
"GoalCreateSchema",
|
||||
]
|
||||
28
app/schemas/account.py
Normal file
28
app/schemas/account.py
Normal file
@@ -0,0 +1,28 @@
|
||||
"""Account schemas"""
|
||||
|
||||
from pydantic import BaseModel
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
|
||||
class AccountCreateSchema(BaseModel):
|
||||
"""Schema for creating account"""
|
||||
name: str
|
||||
account_type: str = "card"
|
||||
description: Optional[str] = None
|
||||
initial_balance: float = 0.0
|
||||
|
||||
|
||||
class AccountSchema(AccountCreateSchema):
|
||||
"""Account response schema"""
|
||||
id: int
|
||||
family_id: int
|
||||
owner_id: int
|
||||
balance: float
|
||||
is_active: bool
|
||||
is_archived: bool
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
29
app/schemas/budget.py
Normal file
29
app/schemas/budget.py
Normal file
@@ -0,0 +1,29 @@
|
||||
"""Budget schemas"""
|
||||
|
||||
from pydantic import BaseModel
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
|
||||
class BudgetCreateSchema(BaseModel):
|
||||
"""Schema for creating budget"""
|
||||
name: str
|
||||
limit_amount: float
|
||||
period: str = "monthly"
|
||||
alert_threshold: float = 80.0
|
||||
category_id: Optional[int] = None
|
||||
start_date: datetime
|
||||
|
||||
|
||||
class BudgetSchema(BudgetCreateSchema):
|
||||
"""Budget response schema"""
|
||||
id: int
|
||||
family_id: int
|
||||
spent_amount: float
|
||||
is_active: bool
|
||||
end_date: Optional[datetime] = None
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
28
app/schemas/category.py
Normal file
28
app/schemas/category.py
Normal file
@@ -0,0 +1,28 @@
|
||||
"""Category schemas"""
|
||||
|
||||
from pydantic import BaseModel
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
|
||||
class CategoryCreateSchema(BaseModel):
|
||||
"""Schema for creating category"""
|
||||
name: str
|
||||
category_type: str
|
||||
emoji: Optional[str] = None
|
||||
color: Optional[str] = None
|
||||
description: Optional[str] = None
|
||||
is_default: bool = False
|
||||
|
||||
|
||||
class CategorySchema(CategoryCreateSchema):
|
||||
"""Category response schema"""
|
||||
id: int
|
||||
family_id: int
|
||||
is_active: bool
|
||||
order: int
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
41
app/schemas/family.py
Normal file
41
app/schemas/family.py
Normal file
@@ -0,0 +1,41 @@
|
||||
"""Family schemas"""
|
||||
|
||||
from pydantic import BaseModel
|
||||
from datetime import datetime
|
||||
from typing import Optional, List
|
||||
|
||||
|
||||
class FamilyMemberSchema(BaseModel):
|
||||
"""Family member schema"""
|
||||
id: int
|
||||
user_id: int
|
||||
role: str
|
||||
can_edit_budget: bool
|
||||
can_manage_members: bool
|
||||
joined_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class FamilyCreateSchema(BaseModel):
|
||||
"""Schema for creating family"""
|
||||
name: str
|
||||
description: Optional[str] = None
|
||||
currency: str = "RUB"
|
||||
notification_level: str = "all"
|
||||
accounting_period: str = "month"
|
||||
|
||||
|
||||
class FamilySchema(FamilyCreateSchema):
|
||||
"""Family response schema"""
|
||||
id: int
|
||||
owner_id: int
|
||||
invite_code: str
|
||||
is_active: bool
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
members: List[FamilyMemberSchema] = []
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
30
app/schemas/goal.py
Normal file
30
app/schemas/goal.py
Normal file
@@ -0,0 +1,30 @@
|
||||
"""Goal schemas"""
|
||||
|
||||
from pydantic import BaseModel
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
|
||||
class GoalCreateSchema(BaseModel):
|
||||
"""Schema for creating goal"""
|
||||
name: str
|
||||
description: Optional[str] = None
|
||||
target_amount: float
|
||||
priority: int = 0
|
||||
target_date: Optional[datetime] = None
|
||||
account_id: Optional[int] = None
|
||||
|
||||
|
||||
class GoalSchema(GoalCreateSchema):
|
||||
"""Goal response schema"""
|
||||
id: int
|
||||
family_id: int
|
||||
current_amount: float
|
||||
is_active: bool
|
||||
is_completed: bool
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
completed_at: Optional[datetime] = None
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
33
app/schemas/transaction.py
Normal file
33
app/schemas/transaction.py
Normal file
@@ -0,0 +1,33 @@
|
||||
"""Transaction schemas"""
|
||||
|
||||
from pydantic import BaseModel
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
|
||||
class TransactionCreateSchema(BaseModel):
|
||||
"""Schema for creating transaction"""
|
||||
amount: float
|
||||
transaction_type: str
|
||||
description: Optional[str] = None
|
||||
notes: Optional[str] = None
|
||||
tags: Optional[str] = None
|
||||
category_id: Optional[int] = None
|
||||
receipt_photo_url: Optional[str] = None
|
||||
transaction_date: datetime
|
||||
|
||||
|
||||
class TransactionSchema(TransactionCreateSchema):
|
||||
"""Transaction response schema"""
|
||||
id: int
|
||||
family_id: int
|
||||
user_id: int
|
||||
account_id: int
|
||||
is_confirmed: bool
|
||||
is_recurring: bool
|
||||
recurrence_pattern: Optional[str] = None
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
26
app/schemas/user.py
Normal file
26
app/schemas/user.py
Normal file
@@ -0,0 +1,26 @@
|
||||
"""User schemas"""
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
|
||||
class UserCreateSchema(BaseModel):
|
||||
"""Schema for creating user"""
|
||||
telegram_id: int
|
||||
username: Optional[str] = None
|
||||
first_name: Optional[str] = None
|
||||
last_name: Optional[str] = None
|
||||
phone: Optional[str] = None
|
||||
|
||||
|
||||
class UserSchema(UserCreateSchema):
|
||||
"""User response schema"""
|
||||
id: int
|
||||
is_active: bool
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
last_activity: Optional[datetime] = None
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
Reference in New Issue
Block a user