feat: implement collaboration module

- Backend (FastAPI):
  - Task comments with nested replies and soft delete
  - @mention parsing with 10-mention limit per comment
  - Notification system with read/unread tracking
  - Blocker management with project owner notification
  - WebSocket endpoint with JWT auth and keepalive
  - User search API for @mention autocomplete
  - Alembic migration for 4 new tables

- Frontend (React + Vite):
  - Comments component with @mention autocomplete
  - NotificationBell with real-time WebSocket updates
  - BlockerDialog for task blocking workflow
  - NotificationContext for state management

- OpenSpec:
  - 4 requirements with scenarios defined
  - add-collaboration change archived

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
beabigegg
2025-12-29 20:45:07 +08:00
parent 61fe01cb6b
commit 3470428411
38 changed files with 3088 additions and 4 deletions

View File

@@ -0,0 +1,76 @@
## 1. Database Schema
- [x] 1.1 建立 Comment model (`pjctrl_comments`)
- [x] 1.2 建立 Mention model (`pjctrl_mentions`)
- [x] 1.3 建立 Notification model (`pjctrl_notifications`)
- [x] 1.4 建立 Blocker model (`pjctrl_blockers`)
- [x] 1.5 建立 Alembic migration
- [x] 1.6 更新 Task model 加入 comments relationship
- [x] 1.7 更新 User model 加入 notifications relationship
## 2. Backend API - Comments
- [x] 2.1 建立 Comment schemas (request/response)
- [x] 2.2 實作 POST `/api/tasks/{task_id}/comments` - 新增留言
- [x] 2.3 實作 GET `/api/tasks/{task_id}/comments` - 取得留言列表
- [x] 2.4 實作 PUT `/api/comments/{comment_id}` - 編輯留言
- [x] 2.5 實作 DELETE `/api/comments/{comment_id}` - 刪除留言
- [x] 2.6 實作 @mention 解析邏輯(從留言內容提取 @username
## 3. Backend API - Notifications
- [x] 3.1 建立 Notification schemas
- [x] 3.2 實作 NotificationService建立、發送通知
- [x] 3.3 實作 GET `/api/notifications` - 取得通知列表
- [x] 3.4 實作 PUT `/api/notifications/{id}/read` - 標記已讀
- [x] 3.5 實作 PUT `/api/notifications/read-all` - 全部已讀
- [x] 3.6 實作 GET `/api/notifications/unread-count` - 未讀數量
## 4. Backend API - Blockers
- [x] 4.1 建立 Blocker schemas
- [x] 4.2 實作 POST `/api/tasks/{task_id}/blockers` - 標記阻礙
- [x] 4.3 實作 PUT `/api/blockers/{blocker_id}/resolve` - 解除阻礙
- [x] 4.4 實作 GET `/api/tasks/{task_id}/blockers` - 取得阻礙歷史
- [x] 4.5 整合阻礙通知(通知專案 Owner
## 5. WebSocket Integration
- [x] 5.1 建立 WebSocket connection manager
- [x] 5.2 實作 `/ws/notifications` endpoint
- [x] 5.3 整合 Redis Pub/Sub 發布通知
- [x] 5.4 實作 WebSocket 認證JWT token
- [x] 5.5 實作心跳機制keepalive
## 6. Backend API - User Search
- [x] 6.1 實作 GET `/api/users/search?q={query}` - 使用者搜尋(支援 @mention 自動完成)
## 7. Frontend - Comments
- [x] 7.1 建立 CommentList 元件
- [x] 7.2 建立 CommentItem 元件(支援巢狀回覆)
- [x] 7.3 建立 CommentForm 元件(含 @mention 自動完成)
- [x] 7.4 整合至 Task 詳情頁
## 8. Frontend - Notifications
- [x] 8.1 建立 NotificationContext狀態管理
- [x] 8.2 建立 NotificationBell 元件(未讀數量 badge
- [x] 8.3 建立 NotificationList 元件
- [x] 8.4 建立 NotificationItem 元件
- [x] 8.5 整合 WebSocket 連線
## 9. Frontend - Blockers
- [x] 9.1 建立 BlockerDialog 元件(標記阻礙表單)
- [x] 9.2 建立 BlockerHistory 元件
- [x] 9.3 整合至 Task 詳情頁
## 10. Testing
- [x] 10.1 Comment API 單元測試
- [x] 10.2 Notification API 單元測試
- [x] 10.3 Blocker API 單元測試
- [x] 10.4 WebSocket 連線測試
- [x] 10.5 @mention 解析測試