
This commit introduces significant updates to the cost management functionality, including: - New endpoints for retrieving cost summaries and generating expenses from lists, improving user interaction with financial data. - Implementation of a service layer for cost-related logic, encapsulating the core business rules for calculating cost summaries and managing expenses. - Introduction of a financial activity endpoint to consolidate user expenses and settlements, enhancing the user experience by providing a comprehensive view of financial activities. - Refactoring of existing code to improve maintainability and clarity, including the addition of new exception handling for financial conflicts. These changes aim to streamline cost management processes and enhance the overall functionality of the application.
35 lines
1012 B
Python
35 lines
1012 B
Python
from pydantic import BaseModel, validator
|
|
from typing import Optional, List
|
|
from datetime import datetime
|
|
|
|
class RecurrencePatternBase(BaseModel):
|
|
type: str
|
|
interval: int = 1
|
|
days_of_week: Optional[List[int]] = None
|
|
end_date: Optional[datetime] = None
|
|
max_occurrences: Optional[int] = None
|
|
|
|
@validator('type')
|
|
def type_must_be_valid(cls, v):
|
|
if v not in ['daily', 'weekly', 'monthly', 'yearly']:
|
|
raise ValueError("type must be one of 'daily', 'weekly', 'monthly', 'yearly'")
|
|
return v
|
|
|
|
@validator('days_of_week')
|
|
def days_of_week_must_be_valid(cls, v):
|
|
if v:
|
|
for day in v:
|
|
if not 0 <= day <= 6:
|
|
raise ValueError("days_of_week must be between 0 and 6")
|
|
return v
|
|
|
|
class RecurrencePatternCreate(RecurrencePatternBase):
|
|
pass
|
|
|
|
class RecurrencePatternPublic(RecurrencePatternBase):
|
|
id: int
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
class Config:
|
|
orm_mode = True |