File size: 4,964 Bytes
1f70d93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
"""
Pydantic models for Todo API

Defines request and response models for todo operations:
- TodoCreate: Request model for creating a new todo
- TodoUpdate: Request model for updating an existing todo
- TodoResponse: Response model for todo data
"""

from pydantic import BaseModel, Field
from datetime import datetime
from typing import Optional, List
from enum import Enum


class PriorityEnum(str, Enum):
    """Priority levels for tasks"""
    HIGH = "HIGH"
    MEDIUM = "MEDIUM"
    LOW = "LOW"


class RecurrenceEnum(str, Enum):
    """Recurrence patterns for tasks"""
    NONE = "NONE"
    DAILY = "DAILY"
    WEEKLY = "WEEKLY"
    MONTHLY = "MONTHLY"


class TodoCreate(BaseModel):
    """Request model for creating a new todo"""
    description: str = Field(..., min_length=1, max_length=500, description="Task description (1-500 characters)")
    priority: Optional[PriorityEnum] = Field(default=PriorityEnum.MEDIUM, description="Task priority level")
    tags: Optional[List[str]] = Field(default=[], description="Array of tags for categorization")
    due_date: Optional[datetime] = Field(None, description="Deadline for the task")
    recurrence_type: Optional[RecurrenceEnum] = Field(default=RecurrenceEnum.NONE, description="Recurrence pattern")
    reminder_time: Optional[int] = Field(default=10, description="Minutes before due time for notification")

    model_config = {
        "json_schema_extra": {
            "examples": [
                {
                    "description": "Buy groceries",
                    "priority": "MEDIUM",
                    "tags": ["shopping", "food"],
                    "due_date": "2025-12-31T18:00:00",
                    "recurrence_type": "NONE",
                    "reminder_time": 10
                }
            ]
        }
    }


class TodoUpdate(BaseModel):
    """Request model for updating a todo (partial update)"""
    description: Optional[str] = Field(None, min_length=1, max_length=500, description="Updated task description (optional)")
    completed: Optional[bool] = Field(None, description="Completion status (optional)")
    priority: Optional[PriorityEnum] = Field(None, description="Task priority level (optional)")
    tags: Optional[List[str]] = Field(None, description="Array of tags for categorization (optional)")
    due_date: Optional[datetime] = Field(None, description="Deadline for the task (optional)")
    recurrence_type: Optional[RecurrenceEnum] = Field(None, description="Recurrence pattern (optional)")
    reminder_time: Optional[int] = Field(None, description="Minutes before due time for notification (optional)")

    model_config = {
        "json_schema_extra": {
            "examples": [
                {
                    "completed": True
                },
                {
                    "description": "Buy groceries and milk"
                },
                {
                    "description": "Complete project documentation",
                    "completed": True,
                    "priority": "HIGH",
                    "tags": ["work", "urgent"],
                    "due_date": "2025-12-31T18:00:00",
                    "recurrence_type": "WEEKLY",
                    "reminder_time": 15
                }
            ]
        }
    }


class TodoResponse(BaseModel):
    """Response model for todo data"""
    id: int = Field(..., description="Unique todo identifier")
    description: str = Field(..., description="Task description")
    completed: bool = Field(..., description="Whether the task is completed")
    priority: PriorityEnum = Field(default=PriorityEnum.MEDIUM, description="Task priority level")
    tags: List[str] = Field(default=[], description="Array of tags for categorization")
    due_date: Optional[datetime] = Field(None, description="Deadline for the task")
    recurrence_type: RecurrenceEnum = Field(default=RecurrenceEnum.NONE, description="Recurrence pattern")
    reminder_time: int = Field(default=10, description="Minutes before due time for notification")
    user_id: Optional[int] = Field(None, description="User ID who owns this todo")
    created_at: datetime = Field(..., description="Creation timestamp (UTC, ISO 8601)")
    updated_at: datetime = Field(..., description="Last modification timestamp (UTC, ISO 8601)")

    model_config = {
        "json_schema_extra": {
            "examples": [
                {
                    "id": 1,
                    "description": "Buy groceries",
                    "completed": False,
                    "priority": "MEDIUM",
                    "tags": ["shopping", "food"],
                    "due_date": "2025-12-31T18:00:00",
                    "recurrence_type": "NONE",
                    "reminder_time": 10,
                    "user_id": 1,
                    "created_at": "2025-12-28T10:00:00.123456",
                    "updated_at": "2025-12-28T10:00:00.123456"
                }
            ]
        }
    }