
Create a full-featured task management API with the following components: - RESTful CRUD operations for tasks - Task status and priority management - SQLite database with SQLAlchemy ORM - Alembic migrations - Health check endpoint - Comprehensive API documentation
73 lines
1.9 KiB
Python
73 lines
1.9 KiB
Python
"""
|
|
Task schemas for validation and serialization.
|
|
"""
|
|
from datetime import datetime
|
|
from typing import Optional
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
from app.models.task import TaskPriority, TaskStatus
|
|
|
|
|
|
# Shared properties
|
|
class TaskBase(BaseModel):
|
|
"""
|
|
Base properties shared by all task schemas.
|
|
"""
|
|
title: str = Field(..., min_length=1, max_length=255, description="Task title")
|
|
description: Optional[str] = Field(None, description="Task description")
|
|
status: TaskStatus = Field(default=TaskStatus.TODO, description="Task status")
|
|
priority: TaskPriority = Field(default=TaskPriority.MEDIUM, description="Task priority")
|
|
due_date: Optional[datetime] = Field(None, description="Task due date")
|
|
|
|
|
|
# Properties to receive on task creation
|
|
class TaskCreate(TaskBase):
|
|
"""
|
|
Properties to receive on task creation.
|
|
"""
|
|
pass
|
|
|
|
|
|
# Properties to receive on task update
|
|
class TaskUpdate(BaseModel):
|
|
"""
|
|
Properties to receive on task update.
|
|
"""
|
|
title: Optional[str] = Field(None, min_length=1, max_length=255, description="Task title")
|
|
description: Optional[str] = Field(None, description="Task description")
|
|
status: Optional[TaskStatus] = Field(None, description="Task status")
|
|
priority: Optional[TaskPriority] = Field(None, description="Task priority")
|
|
due_date: Optional[datetime] = Field(None, description="Task due date")
|
|
|
|
|
|
# Properties shared by models stored in DB
|
|
class TaskInDBBase(TaskBase):
|
|
"""
|
|
Properties shared by models stored in DB.
|
|
"""
|
|
id: int
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
class Config:
|
|
"""
|
|
Pydantic configuration.
|
|
"""
|
|
from_attributes = True
|
|
|
|
|
|
# Properties to return to client
|
|
class Task(TaskInDBBase):
|
|
"""
|
|
Properties to return to client.
|
|
"""
|
|
pass
|
|
|
|
|
|
# Properties stored in DB
|
|
class TaskInDB(TaskInDBBase):
|
|
"""
|
|
Properties stored in DB.
|
|
"""
|
|
pass |