feat: 站内通知
All checks were successful
构建并部署前端到生产环境 / build-and-deploy (push) Successful in 1m29s

This commit is contained in:
luo
2026-07-25 11:08:03 +08:00
parent 3929156ef4
commit 9c1c296d2e
10 changed files with 394 additions and 3 deletions

View File

@@ -0,0 +1,19 @@
# Change: Add personal customer notifications
## Why
个人客户缺少统一的站内通知入口,无法查看业务通知、获取未读数量或管理通知已读状态。
## What Changes
- 增加个人客户通知列表查询接口,支持分页和固定倒序排列。
- 增加单条通知已读和全部通知已读接口。
- 增加个人客户通知未读数查询接口。
- 限制通知数据仅返回当前认证客户可见且未过期的业务通知。
- 统一返回通知内容、关联资源、通知级别、已读状态及时间信息。
## Impact
- Affected specs: `personal-notifications`
- Affected code: 个人客户通知 API、通知列表入口、未读数展示和已读状态处理
- No breaking changes to existing APIs

View File

@@ -0,0 +1,56 @@
## ADDED Requirements
### Requirement: Personal customers SHALL be able to query notifications
The system SHALL provide `GET /api/c/v1/notifications` for authenticated personal customers. The endpoint SHALL return only visible, unexpired business notifications for the current customer, ordered by creation time descending and notification ID descending.
#### Scenario: Query the first notification page
- **WHEN** an authenticated customer requests the notification list without pagination parameters
- **THEN** the system SHALL return page 1 with up to 20 notifications
- **AND** the response SHALL include `items`, `page`, `size`, and `total`
#### Scenario: Apply valid pagination
- **WHEN** the request includes `page` from 1 to 10000 and `page_size` from 1 to 50
- **THEN** the system SHALL return the requested page and page size
#### Scenario: Reject invalid pagination
- **WHEN** `page` or `page_size` is outside its allowed range
- **THEN** the system SHALL return a parameter validation error
### Requirement: Notification items SHALL expose client-readable status and metadata
Each notification item SHALL include `id`, `title`, `body`, `type`, `category`, `severity`, `ref_type`, `ref_id`, `ref_key`, `is_read`, `created_at`, and nullable `read_at`.
#### Scenario: Return an unread notification
- **WHEN** a visible notification has not been read by the current customer
- **THEN** the system SHALL return `is_read: false` and `read_at: null`
### Requirement: Personal customers SHALL be able to mark one notification as read
The system SHALL provide `PUT /api/c/v1/notifications/{id}/read` for authenticated personal customers. The operation SHALL be idempotent and SHALL only update a notification visible to the current customer.
#### Scenario: Mark a visible unread notification
- **WHEN** the customer marks a visible unread notification as read
- **THEN** the system SHALL set its read state and return `{ "success": true }`
#### Scenario: Mark an unavailable or already-read notification
- **WHEN** the notification does not exist, belongs to another customer, or is already read
- **THEN** the system SHALL return `{ "success": true }` without exposing ownership information
### Requirement: Personal customers SHALL be able to mark all notifications as read
The system SHALL provide `PUT /api/c/v1/notifications/read-all` to mark all visible, unexpired, unread business notifications for the current customer as read.
#### Scenario: Mark all unread notifications
- **WHEN** the customer calls the mark-all-read endpoint
- **THEN** the system SHALL return the number of notifications actually updated in `updated_count`
- **AND** repeated calls SHALL remain successful and return zero when nothing needs updating
### Requirement: Personal customers SHALL be able to query unread count
The system SHALL provide `GET /api/c/v1/notifications/unread-count`. The count SHALL include only visible, unexpired business notifications and SHALL exclude platform sync and system operations notifications.
#### Scenario: Return unread count and badge text
- **WHEN** an authenticated customer queries the unread count
- **THEN** the system SHALL return numeric `count` and string `display_count`
- **AND** `display_count` SHALL be `99+` when `count` exceeds 99

View File

@@ -0,0 +1,26 @@
## 1. API and Data Contract
- [x] 1.1 Define the client-side personal notification item and paginated list contract
- [x] 1.2 Define the client-side unread count and read-operation contracts
- [x] 1.3 Add authenticated notification API wrappers
## 2. Notification Behavior
- [ ] 2.1 Return only current customer's visible, unexpired business notifications
- [ ] 2.2 Apply creation-time and notification-ID descending ordering
- [ ] 2.3 Support idempotent single-read and read-all operations
- [ ] 2.4 Exclude platform sync and system operations notifications from unread count
## 3. Client Entry
- [x] 3.1 Add the personal notification list entry and pagination handling
- [x] 3.2 Add unread-count display and refresh behavior
- [x] 3.3 Mark notifications read from list actions and support mark-all-read
## 4. Verification
- [ ] 4.1 Test authentication, pagination limits, ordering, and visibility isolation
- [ ] 4.2 Test idempotent read behavior and unread-count updates
- [x] 4.3 Verify the H5 build and unified success/error response handling
> Note: The repository contains the H5 client only. Tasks 2.1-2.4 and 4.1-4.2 require implementation and verification in the backend service repository.