Backend: - Add uuid, sync_version, is_deleted fields to all syncable models - Add SyncSettings model for WebDAV configuration (AES-256-GCM encrypted passwords) - Add crypto.py: AES-256-GCM encryption derived from JWT_SECRET via PBKDF2 - Add sync_lock.py: thread-level sync lock with 503 middleware for write blocking - Add webdav.py: WebDAV client using requests (PUT/GET/MKCOL/DELETE) - Add sync_service.py: push/pull/bidirectional merge with LWW conflict resolution - Add sync router with 8 endpoints: config, test, push, pull, sync, status, remote delete - Add UUID backfill for existing records in init_db() - Add SQLAlchemy before_update event to auto-increment sync_version - Register sync middleware to block writes during sync (503) Frontend: - Add sync API client (WebUI/src/api/sync.ts) - Add useSyncStore with config, test, push/pull/sync operations - Add WebDAV config + sync UI in SettingsView - Add 503 status code handling in axios interceptor - Add uuid field to all TypeScript type definitions Scripts: - Add scripts/start.bat and scripts/stop.bat for project management Design doc: docs/plan/webdav-sync-design.md
123 lines
3.4 KiB
Python
123 lines
3.4 KiB
Python
from pydantic import BaseModel, Field, field_validator
|
|
from datetime import datetime, date
|
|
from typing import Optional, List
|
|
|
|
from app.schemas.category import CategoryResponse
|
|
from app.schemas.task import TaskResponse
|
|
|
|
|
|
# ============ GoalStep Schemas ============
|
|
|
|
class GoalStepBase(BaseModel):
|
|
title: str = Field(..., max_length=200)
|
|
step_type: str = Field(..., pattern="^(phase|milestone)$")
|
|
status: str = Field(default="pending", pattern="^(pending|in_progress|completed)$")
|
|
target_date: Optional[date] = None
|
|
parent_id: Optional[int] = None
|
|
sort_order: int = Field(default=0)
|
|
|
|
|
|
class GoalStepCreate(GoalStepBase):
|
|
pass
|
|
|
|
|
|
class GoalStepUpdate(BaseModel):
|
|
title: Optional[str] = Field(None, max_length=200)
|
|
step_type: Optional[str] = Field(None, pattern="^(phase|milestone)$")
|
|
status: Optional[str] = Field(None, pattern="^(pending|in_progress|completed)$")
|
|
target_date: Optional[date] = None
|
|
parent_id: Optional[int] = None
|
|
sort_order: Optional[int] = None
|
|
|
|
@property
|
|
def clearable_fields(self) -> set:
|
|
return {"target_date", "parent_id"}
|
|
|
|
|
|
class GoalStepResponse(GoalStepBase):
|
|
id: int
|
|
uuid: Optional[str] = None
|
|
goal_id: int
|
|
reached_at: Optional[datetime] = None
|
|
created_at: datetime
|
|
children: List["GoalStepResponse"] = []
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
# ============ GoalReview Schemas ============
|
|
|
|
class GoalReviewCreate(BaseModel):
|
|
content: str = Field(..., min_length=1)
|
|
rating: Optional[int] = Field(None, ge=1, le=5)
|
|
|
|
|
|
class GoalReviewResponse(BaseModel):
|
|
id: int
|
|
uuid: Optional[str] = None
|
|
goal_id: int
|
|
content: str
|
|
rating: Optional[int] = None
|
|
created_at: datetime
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
# ============ Goal Schemas ============
|
|
|
|
class GoalBase(BaseModel):
|
|
title: str = Field(..., max_length=200)
|
|
description: Optional[str] = None
|
|
status: str = Field(default="active", pattern="^(active|paused|completed|abandoned)$")
|
|
target_date: Optional[date] = None
|
|
category_id: Optional[int] = None
|
|
color: str = Field(default="#FFB7C5", max_length=20)
|
|
icon: str = Field(default="flag", max_length=50)
|
|
sort_order: int = Field(default=0)
|
|
|
|
|
|
class GoalCreate(GoalBase):
|
|
pass
|
|
|
|
|
|
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)$")
|
|
target_date: Optional[date] = None
|
|
category_id: Optional[int] = None
|
|
color: Optional[str] = Field(None, max_length=20)
|
|
icon: Optional[str] = Field(None, max_length=50)
|
|
sort_order: Optional[int] = None
|
|
|
|
@property
|
|
def clearable_fields(self) -> set:
|
|
return {"description", "target_date", "category_id"}
|
|
|
|
|
|
class GoalListResponse(GoalBase):
|
|
id: int
|
|
uuid: Optional[str] = None
|
|
progress: int
|
|
completed_at: Optional[datetime] = None
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
category: Optional[CategoryResponse] = None
|
|
total_steps: int = 0
|
|
completed_steps: int = 0
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class GoalDetailResponse(GoalListResponse):
|
|
steps: List[GoalStepResponse] = []
|
|
reviews: List[GoalReviewResponse] = []
|
|
tasks: List[TaskResponse] = []
|
|
|
|
|
|
class GoalStatusUpdate(BaseModel):
|
|
status: str = Field(..., pattern="^(active|paused|completed|abandoned)$")
|