feat: add cumulative checkin tracking mode for goals
Goals can now choose between milestone-based progress (existing) and cumulative checkin-based progress (new). Cumulative mode supports cross-unit conversion (e.g. kcal → g fat) via a configurable conversion rate. New GoalCheckin model stores daily inputs; progress auto-recalculates on every checkin C/U/D. Backup import/export covers the new table. Frontend GoalDialog, GoalDetailPage and GoalPage cards adapt to show cumulative progress or milestone progress based on track_type. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,37 @@ from app.schemas.category import CategoryResponse
|
||||
from app.schemas.task import TaskResponse
|
||||
|
||||
|
||||
# ============ GoalCheckin Schemas ============
|
||||
|
||||
class GoalCheckinCreate(BaseModel):
|
||||
value: float = Field(..., gt=0)
|
||||
note: Optional[str] = None
|
||||
checkin_date: date
|
||||
|
||||
|
||||
class GoalCheckinUpdate(BaseModel):
|
||||
value: Optional[float] = Field(None, gt=0)
|
||||
note: Optional[str] = None
|
||||
checkin_date: Optional[date] = None
|
||||
|
||||
@property
|
||||
def clearable_fields(self) -> set:
|
||||
return {"note"}
|
||||
|
||||
|
||||
class GoalCheckinResponse(BaseModel):
|
||||
id: int
|
||||
uuid: Optional[str] = None
|
||||
goal_id: int
|
||||
value: float
|
||||
note: Optional[str] = None
|
||||
checkin_date: date
|
||||
created_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
# ============ GoalStep Schemas ============
|
||||
|
||||
class GoalStepBase(BaseModel):
|
||||
@@ -71,6 +102,11 @@ class GoalBase(BaseModel):
|
||||
title: str = Field(..., max_length=200)
|
||||
description: Optional[str] = None
|
||||
status: str = Field(default="active", pattern="^(active|paused|completed|abandoned)$")
|
||||
track_type: str = Field(default="milestone", pattern="^(milestone|cumulative)$")
|
||||
target_value: Optional[float] = None
|
||||
target_unit: Optional[str] = Field(None, max_length=20)
|
||||
input_unit: Optional[str] = Field(None, max_length=20)
|
||||
conversion_rate: float = Field(default=1.0)
|
||||
target_date: Optional[date] = None
|
||||
category_id: Optional[int] = None
|
||||
color: str = Field(default="#FFB7C5", max_length=20)
|
||||
@@ -86,6 +122,11 @@ class GoalUpdate(BaseModel):
|
||||
title: Optional[str] = Field(None, max_length=200)
|
||||
description: Optional[str] = None
|
||||
status: Optional[str] = Field(None, pattern="^(active|paused|completed|abandoned)$")
|
||||
track_type: Optional[str] = Field(None, pattern="^(milestone|cumulative)$")
|
||||
target_value: Optional[float] = None
|
||||
target_unit: Optional[str] = Field(None, max_length=20)
|
||||
input_unit: Optional[str] = Field(None, max_length=20)
|
||||
conversion_rate: Optional[float] = None
|
||||
target_date: Optional[date] = None
|
||||
category_id: Optional[int] = None
|
||||
color: Optional[str] = Field(None, max_length=20)
|
||||
@@ -94,13 +135,15 @@ class GoalUpdate(BaseModel):
|
||||
|
||||
@property
|
||||
def clearable_fields(self) -> set:
|
||||
return {"description", "target_date", "category_id"}
|
||||
return {"description", "target_date", "category_id",
|
||||
"target_value", "target_unit", "input_unit"}
|
||||
|
||||
|
||||
class GoalListResponse(GoalBase):
|
||||
id: int
|
||||
uuid: Optional[str] = None
|
||||
progress: int
|
||||
current_value: float = 0
|
||||
completed_at: Optional[datetime] = None
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
@@ -115,6 +158,7 @@ class GoalListResponse(GoalBase):
|
||||
class GoalDetailResponse(GoalListResponse):
|
||||
steps: List[GoalStepResponse] = []
|
||||
reviews: List[GoalReviewResponse] = []
|
||||
checkins: List[GoalCheckinResponse] = []
|
||||
tasks: List[TaskResponse] = []
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user