| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- """
- Pydantic schemas for Task API.
- Defines request and response models for task operations.
- """
- from datetime import datetime
- from typing import Optional, Any
- from pydantic import BaseModel, Field
- class TaskCreate(BaseModel):
- """Schema for creating a new task."""
-
- project_id: str = Field(..., min_length=1, description="Project ID this task belongs to")
- name: str = Field(..., min_length=1, description="Task name")
- data: dict = Field(..., description="Task data (JSON object)")
- assigned_to: Optional[str] = Field(None, description="User ID assigned to this task")
-
- class Config:
- json_schema_extra = {
- "example": {
- "project_id": "proj_123abc",
- "name": "Annotate Image Batch 1",
- "data": {
- "image_url": "https://example.com/image1.jpg",
- "metadata": {"batch": 1}
- },
- "assigned_to": "user_001"
- }
- }
- class TaskUpdate(BaseModel):
- """Schema for updating an existing task."""
-
- name: Optional[str] = Field(None, min_length=1, description="Task name")
- data: Optional[dict] = Field(None, description="Task data (JSON object)")
- status: Optional[str] = Field(None, description="Task status (pending, in_progress, completed)")
- assigned_to: Optional[str] = Field(None, description="User ID assigned to this task")
-
- class Config:
- json_schema_extra = {
- "example": {
- "name": "Updated Task Name",
- "status": "in_progress",
- "assigned_to": "user_002"
- }
- }
- class TaskResponse(BaseModel):
- """Schema for task response."""
-
- id: str = Field(..., description="Task unique identifier")
- project_id: str = Field(..., description="Project ID this task belongs to")
- name: str = Field(..., description="Task name")
- data: dict = Field(..., description="Task data (JSON object)")
- status: str = Field(..., description="Task status (pending, in_progress, completed)")
- assigned_to: Optional[str] = Field(None, description="User ID assigned to this task")
- created_at: datetime = Field(..., description="Task creation timestamp")
- progress: float = Field(default=0.0, description="Task completion progress (0.0 to 1.0)")
-
- class Config:
- json_schema_extra = {
- "example": {
- "id": "task_456def",
- "project_id": "proj_123abc",
- "name": "Annotate Image Batch 1",
- "data": {
- "image_url": "https://example.com/image1.jpg",
- "metadata": {"batch": 1}
- },
- "status": "in_progress",
- "assigned_to": "user_001",
- "created_at": "2024-01-12T11:00:00",
- "progress": 0.5
- }
- }
|