feat(api): 补齐 /me/* 命名空间,恢复 17 个 404 调用 + 修 /me/status 过期桩
背景:小程序 services/*.js 按 REST 规范(§16 / §22-§40 / §80 / §83-§84)统一调用
/me/*,但后端从未注册 /me 基路径,个人资料、照片、择偶条件、隐私设置、关系状态、
我的举报/申诉等约 17 个调用全部 404。
后端
- 新增 me/controller/MeController:把既有 service 能力暴露到规范路径(纯委托,不复制
业务规则,AGENTS.md #26)。旧路径(/profile/*、/photos、/relationship/*、
/account/privacy-settings、/risk/reports/my、/appeals/my)全部保留。
- 响应形状按小程序 JSDoc 适配(小程序被 86 页引用,是权威契约):
· /me/relationship-status 返回 status(旧 /relationship/status 返回 relationshipStatus,
字段名不同,前端读的是 result.status)
· /me/profile/review-status 返回 {status, items, submittedAt, reviewedAt},时间统一 epoch 毫秒
· /me/profile/submit-review 返回 {reviewStatus, submittedAt}
- 小程序三条历史写法一并兼容:/me/privacy-settings、/me/photos/{id}/main、/me/appeals
修复
- AuthService.getMeStatus:verified / profileStatus / reviewStatus 三项写死为
false / not_started / not_submitted,注释标注"Phase 03/04/05 填充",但那三个 Phase
早已交付,导致 /me/status 长期返回错误的实名与审核状态。改为 capabilityService
+ userProfileMapper + reviewTaskMapper 的真实来源(与首页聚合同一判定)。
- PhotoController.deletePhoto:原用 ((Map<?,?>) p).get("id") 强转 UserPhoto 实体,
必然抛 ClassCastException,删除照片恒定 500。改用实体主键比对。
- PhotoService.setMainAvatar(新增):数据模型以 photo_type='avatar' 标识头像(见
UserPhotoMapper#findAvatar),无 is_main 字段,故"设主图"= 换类型并保证至多一张。
注意:插入该方法时曾把 deletePhoto 原有的 @Transactional 挤到新方法上,导致
"Transactional is not a repeatable annotation" 并引发 Lombok 全面停摆(满屏
找不到 getter/setter),已修正注解归属。
验证
- 后端全量:299 tests / 0 failures / 0 errors / 3 skipped / BUILD SUCCESS(+2 为新增契约测试)
- 新增 MeRouteContractTest(2 例):同时断言 HTTP 方法,锁定 21 条 /me/* 与 13 条旧路径
- 小程序 tsc --noEmit 通过;UI 契约门禁 13/13
文档
- STATUS.md:/me/* 从"待裁决"改为"已完成";核心待清债务 1 项 → 0 项
- API_INVENTORY.md:顶部"待收敛"警告改为"已收敛",补全 /me/* 端点表
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
package com.danyang.match.platform.contract;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* 路由契约测试:锁定 {@code /me/*} 本人资源命名空间。
|
||||
*
|
||||
* <p>背景(2026-09-16):小程序 {@code services/*.js} 按 {@code REST API 接口详细设计规范.md}
|
||||
* (§16 / §22-§40 / §80 / §83-§84)统一调用 {@code /me/*},但后端此前从未注册 {@code /me} 基路径,
|
||||
* 导致个人资料、照片、择偶条件、隐私设置、关系状态、我的举报/申诉等约 17 个调用全部 404。
|
||||
*
|
||||
* <p>本测试同时断言 <b>HTTP 方法</b>,因为"路径注册了但方法不对"仍会让前端收到 405——
|
||||
* 例如 {@code /me/relationship-status} 前端用 PATCH,写成 PUT 同样不可用。
|
||||
*
|
||||
* <p>旧路径({@code /profile/*}、{@code /photos}、{@code /relationship/status} 等)必须继续保留,
|
||||
* 管理端与既有测试依赖它们,故一并断言。
|
||||
*/
|
||||
@SpringBootTest
|
||||
@ActiveProfiles("test")
|
||||
class MeRouteContractTest {
|
||||
|
||||
/** 按名字取 MVC 的 HandlerMapping —— Actuator 也注册了一个同类型 bean,按类型注入会歧义 */
|
||||
@Autowired
|
||||
@Qualifier("requestMappingHandlerMapping")
|
||||
private RequestMappingHandlerMapping handlerMapping;
|
||||
|
||||
/** 上下文已注册的 "METHOD URL" 集合;无方法限定的记为 "ANY URL" */
|
||||
private Set<String> routes() {
|
||||
Set<String> out = new HashSet<>();
|
||||
handlerMapping.getHandlerMethods().forEach((info, handler) -> {
|
||||
Set<RequestMethod> methods = info.getMethodsCondition().getMethods();
|
||||
for (String pattern : info.getPatternValues()) {
|
||||
if (methods.isEmpty()) {
|
||||
out.add("ANY " + pattern);
|
||||
} else {
|
||||
for (RequestMethod method : methods) {
|
||||
out.add(method.name() + " " + pattern);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return out;
|
||||
}
|
||||
|
||||
private void assertRoute(Set<String> routes, String method, String path) {
|
||||
assertTrue(routes.contains(method + " " + path), "缺少路由 " + method + " " + path);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("小程序依赖的 /me/* 个人资源路由必须全部注册")
|
||||
void meRoutesRegistered() {
|
||||
Set<String> r = routes();
|
||||
|
||||
// 账号状态(REST §16)
|
||||
assertRoute(r, "GET", "/me/status");
|
||||
|
||||
// 个人资料(REST §22-§23、第二十一章)
|
||||
assertRoute(r, "GET", "/me/profile");
|
||||
assertRoute(r, "PUT", "/me/profile");
|
||||
assertRoute(r, "PATCH", "/me/profile/basic");
|
||||
assertRoute(r, "GET", "/me/profile/completion");
|
||||
|
||||
// 资料审核(REST §37 / §39)——前端走 /me/profile/review-status
|
||||
assertRoute(r, "GET", "/me/profile/review-status");
|
||||
assertRoute(r, "POST", "/me/profile/submit-review");
|
||||
|
||||
// 择偶条件(REST §34-§35)
|
||||
assertRoute(r, "GET", "/me/preferences");
|
||||
assertRoute(r, "PUT", "/me/preferences");
|
||||
|
||||
// 照片(REST §29-§32 + 小程序专有的设主图)
|
||||
assertRoute(r, "GET", "/me/photos");
|
||||
assertRoute(r, "POST", "/me/photos/upload-token");
|
||||
assertRoute(r, "DELETE", "/me/photos/{photoId}");
|
||||
assertRoute(r, "PUT", "/me/photos/{photoId}/main");
|
||||
|
||||
// 隐私设置(REST 第九十一章用 /me/privacy;/me/privacy-settings 为小程序历史写法)
|
||||
assertRoute(r, "GET", "/me/privacy");
|
||||
assertRoute(r, "PATCH", "/me/privacy");
|
||||
assertRoute(r, "GET", "/me/privacy-settings");
|
||||
assertRoute(r, "PUT", "/me/privacy-settings");
|
||||
|
||||
// 关系状态(REST §83-§84)——前端用 PATCH,不是 PUT
|
||||
assertRoute(r, "GET", "/me/relationship-status");
|
||||
assertRoute(r, "PATCH", "/me/relationship-status");
|
||||
|
||||
// 我的举报 / 申诉(REST §80 + 小程序申诉列表)
|
||||
assertRoute(r, "GET", "/me/reports");
|
||||
assertRoute(r, "GET", "/me/appeals");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("被 /me/* 兼容的旧路径必须继续保留(管理端与既有测试依赖)")
|
||||
void legacyRoutesKept() {
|
||||
Set<String> r = routes();
|
||||
|
||||
assertRoute(r, "GET", "/profile/me");
|
||||
assertRoute(r, "PUT", "/profile/me");
|
||||
assertRoute(r, "GET", "/profile/preferences");
|
||||
assertRoute(r, "GET", "/profile/privacy");
|
||||
assertRoute(r, "GET", "/photos");
|
||||
assertRoute(r, "POST", "/photos/upload-token");
|
||||
assertRoute(r, "GET", "/relationship/status");
|
||||
assertRoute(r, "PUT", "/relationship/pause");
|
||||
assertRoute(r, "PUT", "/relationship/resume");
|
||||
assertRoute(r, "PUT", "/relationship/getting-to-know");
|
||||
assertRoute(r, "GET", "/risk/reports/my");
|
||||
assertRoute(r, "GET", "/appeals/my");
|
||||
assertRoute(r, "GET", "/account/privacy-settings");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user