DevByte-Community / DevByte-Community/Community-API-Backend

Implement Basic Notification System (V1)

未關閉
#72 0 則留言 0 個 reaction 已指派 1 人 已被 @marrious11 認領 在 GitHub 檢視
主要語言
JavaScript
星號
2
分支
11
PR 合併指標
30 天內沒有已合併 PR

描述

Ticket ID: NOTIF-SYSTEM-001
Priority: Medium

**Feature Description**

Implement a simple notification system that stores and retrieves user notifications based on platform activities. Notifications will be stored in the database and retrieved via API. Users can view, mark as read, and delete notifications.

**Acceptance Criteria**

1. Database Schema ✅

- Create new table:
```
sql

notifications
- id: uuidv7 PRIMARY KEY
- user_id: uuid REFERENCES users(id) ON DELETE CASCADE
- type: VARCHAR(20) -- 'SYSTEM', 'PROJECT', 'EVENT', 'BLOG'
- title: VARCHAR(100)
- message: TEXT
- entity_type: VARCHAR(50) -- 'project', 'event', 'blog', etc.
- entity_id: uuid
- is_read: BOOLEAN DEFAULT false
- created_at: TIMESTAMP DEFAULT NOW()
```

2. Core Notifications (MVP) ✅

- Trigger notifications for:

- Project: User added as contributor, project status changes

- Event: User registered for event, event starting soon (24h)

- Blog: User's blog post is published/commented on

- System: Platform announcements (admin only)

3. API Endpoints ✅
```
text

GET /api/notifications # List notifications (paginated, 20/page)
GET /api/notifications/unread-count # Get unread count for header badge
PUT /api/notifications/:id/read # Mark single as read
PUT /api/notifications/read-all # Mark all user's notifications as read
DELETE /api/notifications/:id # Delete single notification
DELETE /api/notifications # Delete all user's notifications
```

4. Response Format ✅
```
json

{
"success"" true,
"notifications": [
{
"id": "uuid",
"type": "PROJECT",
"title": "Added to Project",
"message": "You were added as a contributor to 'E-commerce Platform'",
"entityType": "project",
"entityId": "project-uuid",
"isRead": false,
"createdAt": "2024-01-15T10:30:00Z",
"metadata": {}
}
],
"total": 45,
"unreadCount": 12,
"page": 1,
"pageSize": 1
...
}
```

5. Filtering & Preferences ✅

- Show all notification types if user preference notification field is true

- Admin system notifications always shown

6. Performance Requirements ✅

- API response time < 100ms

- Indexes on: user_id, is_read, created_at

- Pagination using cursor-based or offset pagination

- Cleanup old notifications (> 90 days) via scheduled job

7. Testing ✅

- Unit tests for notification creation

- Integration tests for API endpoints

- Test preference filtering logic

- Test pagination and ordering (newest first)

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。