-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
60 lines (49 loc) · 1.72 KB
/
Copy pathmodels.py
File metadata and controls
60 lines (49 loc) · 1.72 KB
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
"""
Database models and Pydantic schemas for the Task Manager API
"""
from datetime import datetime
from typing import Optional
from pydantic import BaseModel
from sqlalchemy import Column, Integer, String, DateTime, func
from sqlalchemy.ext.declarative import declarative_base
# Base class for all SQLAlchemy models
Base = declarative_base()
# ===== DATABASE MODELS (SQLAlchemy) =====
# These define the actual database tables
class TaskDB(Base):
"""
The Task table in PostgreSQL.
Columns:
- id: Unique identifier (primary key)
- title: Short title of the task
- description: Longer description
- status: Either 'pending', 'in_progress', or 'completed'
- created_at: When the task was created
"""
__tablename__ = "tasks"
id = Column(Integer, primary_key=True, index=True)
title = Column(String(255), nullable=False)
description = Column(String, nullable=True)
status = Column(String(50), default="pending", nullable=False)
created_at = Column(DateTime(timezone=True), server_default=func.now(), nullable=False)
# ===== PYDANTIC SCHEMAS =====
# These define the structure of data sent/received via the API
class TaskCreate(BaseModel):
"""Schema for creating a new task"""
title: str
description: Optional[str] = None
status: str = "pending"
class TaskUpdate(BaseModel):
"""Schema for updating a task"""
title: Optional[str] = None
description: Optional[str] = None
status: Optional[str] = None
class TaskResponse(BaseModel):
"""Schema for returning a task in API responses"""
id: int
title: str
description: Optional[str]
status: str
created_at: datetime
class Config:
from_attributes = True # Allow creating from ORM objects