Просмотр исходного кода

feat(notification.center.view): S-cfc-381 消息中心/通知查看契约使绿(分页 + 不存在404)

- UserNotificationController.list 新增分页重载:请求带 pageNum 查询参数时命中
  (POST /api/notification/list?pageNum=&pageSize=),返回 Result<Page<UserNotification>>
  (含 total/pageNum/pageSize 分页载体),未读优先+倒序保持;无参请求走原扁平 LIMIT 100
  接口,向后兼容现前端 getNotificationList
- UserNotificationController.read 单条 id 不存在时返回 404(Result.notFound,TC-P-78-E
  「不存在 404」);批量 ids/越权/全部已读行为不变
- API_REFERENCE.md 同步 §4.15 / §4.61.7 端点契约(分页与 404)
E2E Test Bot 1 день назад
Родитель
Сommit
b6080f3b17

+ 28 - 3
cfc-backend/src/main/java/com/etotem/cfc/controller/UserNotificationController.java

@@ -1,6 +1,7 @@
 package com.etotem.cfc.controller;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.etotem.cfc.common.Result;
 import com.etotem.cfc.entity.UserNotification;
 import com.etotem.cfc.mapper.UserNotificationMapper;
@@ -11,6 +12,7 @@ import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestAttribute;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 import java.util.Date;
@@ -28,7 +30,7 @@ public class UserNotificationController {
     @Resource
     private UserNotificationMapper userNotificationMapper;
 
-    @Operation(summary = "通知列表(未读优先,倒序)")
+    @Operation(summary = "通知列表(未读优先,倒序,LIMIT 100 扁平)")
     @PostMapping("/list")
     public Result<List<UserNotification>> list(@RequestAttribute("userId") Long userId) {
         List<UserNotification> list = userNotificationMapper.selectList(
@@ -40,7 +42,26 @@ public class UserNotificationController {
         return Result.success(list);
     }
 
-    @Operation(summary = "标记已读(id 或 ids 数组,缺省标记全部)")
+    /**
+     * 通知列表(分页,SC-P-78「分页」)。请求带 {@code pageNum} 查询参数时命中本方法(org.springframework
+     * 会在同路径下选择更具体的 {@code params} 条件映射),返回含 {@code total/pageNum/pageSize} 的分页载体;
+     * 未带 {@code pageNum} 时走上方扁平 LIMIT 100 接口(向后兼容现有前端)。
+     */
+    @Operation(summary = "通知列表(分页,未读优先倒序;pageNum/pageSize 请求参数)")
+    @PostMapping(value = "/list", params = "pageNum")
+    public Result<Page<UserNotification>> list(@RequestAttribute("userId") Long userId,
+                                               @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
+                                               @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize) {
+        Page<UserNotification> page = userNotificationMapper.selectPage(
+                new Page<>(pageNum, pageSize),
+                new LambdaQueryWrapper<UserNotification>()
+                        .eq(UserNotification::getUserId, userId)
+                        .orderByAsc(UserNotification::getIsRead)
+                        .orderByDesc(UserNotification::getCreatedAt));
+        return Result.success(page);
+    }
+
+    @Operation(summary = "标记已读(id 或 ids 数组,缺省标记全部;id 不存在 → 404)")
     @PostMapping("/read")
     public Result<Boolean> read(@RequestAttribute("userId") Long userId,
                                 @RequestBody(required = false) Map<String, Object> params) {
@@ -48,7 +69,11 @@ public class UserNotificationController {
         Object idsObj = params != null ? params.get("ids") : null;
         if (idObj != null) {
             UserNotification n = userNotificationMapper.selectById(Long.valueOf(idObj.toString()));
-            if (n != null && n.getUserId().equals(userId)) {
+            if (n == null) {
+                // TC-P-78-E「不存在 404」:无此消息 → 404
+                return Result.notFound("消息不存在");
+            }
+            if (n.getUserId().equals(userId)) {
                 n.setIsRead(1);
                 userNotificationMapper.updateById(n);
             }

+ 4 - 4
docs/superpowers/api/API_REFERENCE.md

@@ -833,8 +833,8 @@ find cfc-backend/src/main/java -name "*XxxService.java" -o -name "*XxxController
 | `POST /api/stats/revenue` | 收入统计 |
 | `POST /api/stats/membership` | 会员统计 |
 | `POST /api/stats/trend` | 趋势 |
-| `POST /api/notification/list` | 通知列表 |
-| `POST /api/notification/read` | 标记已读 |
+| `POST /api/notification/list` | 通知列表(分页 `pageNum/pageSize` 查询参数可选,SC-P-78 S-cfc-381) |
+| `POST /api/notification/read` | 标记已读(`id` 不存在 → 404) |
 
 ### 4.16 报告模板管理(`/api/admin/report-template`)
 
@@ -3309,8 +3309,8 @@ W0.2 双配置中心合并:`product_config` 已并入 `service_config`(唯
 ### 4.61.7 消息 / 反馈 / 资料(SC-C-15 / C-16 / C-19 / C-23)
 | 路径 | 请求 | 响应 `data` | 说明 |
 |------|------|-------------|------|
-| `POST /api/notification/list` | 无(取 `userId`) | `UserNotification[]`(未读优先,`LIMIT 100`) | 站内通知 |
-| `POST /api/notification/read` | `{id?}` / `{ids?}` / 空(全部已读) | `Boolean` | 标记已读 |
+| `POST /api/notification/list` | 无(取 `userId`);可选 `pageNum/pageSize` 查询参数 | 无参:`UserNotification[]`(未读优先,`LIMIT 100`);带 `pageNum`:`Page<UserNotification>`(含 `total/pageNum/pageSize`) | 站内通知(SC-P-78,S-cfc-381 补分页) |
+| `POST /api/notification/read` | `{id?}` / `{ids?}` / 空(全部已读) | `Boolean` | 标记已读;`id` 不存在 → 404(TC-P-78-E) |
 | `POST /api/guide/messages/my` | 无(取 `userId`) | `TeacherMessage[]` | 规划师消息 |
 | `POST /api/guide/messages/unread-count` | 无 | `Long` | 未读数 |
 | `POST /api/user/info` / `/api/auth/info` / `/api/family/user/info` | 无(取 `userId`) | **完整 `User`**(仅 `password` 置空) | 个人资料(**无受限投影**,G-02) |