新增:资料页真实化 + 编辑页——/me 读写、PATCH 三态、获赞与作品统计(T3.5-08)
资料页头部三项(展示名 / 头像 / 数字)自此全部来自服务端,176 行硬编码 demo(「萌宠新手(豆豆家长)」/ 24 / 1.8k / 2)退役。 - `PatchField<T>` 承载契约 v1.4.0 的 PATCH 三态(absent 不落键 / clear 落 显式 null / value 落值)。三态必须由类型承载而非 `T?` 加约定:把「不改」 也编码成 null,用户只改昵称就会连头像一起被服务端清掉。 - `UserProfile` 补 nickname / avatarUrl,展示回退 `nickname ?? username` **做在客户端展示层**——服务端 /me 刻意返回 DB 原值,编辑页因此只用原值 预填,避免把展示约定固化成真实昵称。 - `ProfileController`:`/me` 主链路四态 + 两块统计独立三态(统计失败只降级 这一块,不为两个数字丢掉整页);登出 reset 防跨账号泄漏。 - 编辑页维护三态意图而非「当前值整体提交」:昵称 / 头像各有显式清除入口, 未改字段的键根本不进 JSON;空 patch 直接短路(服务端对空 patch 答 400)。 - 昵称校验按**码点**计 1~32 且先 btrim,与 `ck_users_nickname` 对齐; 纯空白是校验失败而非隐式清空。 - `MediaUploader` 的 purpose 参数化 + 复用其六态编排的 `AvatarUploadSheet` (单图、预览确认后才交付 ready assetId,孤儿防护不变)。 - 修复 `/api/v1/me` 端口线路:该端点由 user 服务(:8082)提供,`ApiAuthRepository` 此前只挂 auth(:8081)会得到 404。此前无人消费 me(),故这条错线一直没被 触发;本单是第一个真实消费者,桌面实测即暴露。 测试 526 → 588(+62)。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -26,15 +26,23 @@ class FakeAuthRepository implements AuthRepository {
|
||||
this.loginHandler,
|
||||
this.registerHandler,
|
||||
this.restoreHandler,
|
||||
this.meHandler,
|
||||
this.updateMeHandler,
|
||||
});
|
||||
|
||||
final Future<void> Function()? loginHandler;
|
||||
final Future<void> Function()? registerHandler;
|
||||
final Future<SessionRestoreResult> Function()? restoreHandler;
|
||||
final Future<UserProfile> Function()? meHandler;
|
||||
final Future<UserProfile> Function(UpdateMeRequest)? updateMeHandler;
|
||||
|
||||
int loginCalls = 0;
|
||||
int registerCalls = 0;
|
||||
int logoutCalls = 0;
|
||||
int meCalls = 0;
|
||||
|
||||
/// 收到的 PATCH 载荷(三态断言用:**未改字段不应出现在 map 里**)。
|
||||
final List<Map<String, Object?>> updateMePayloads = [];
|
||||
|
||||
@override
|
||||
Future<void> login({required String username, required String password}) {
|
||||
@@ -64,9 +72,51 @@ class FakeAuthRepository implements AuthRepository {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<UserProfile> me() async => throw UnimplementedError();
|
||||
Future<UserProfile> me() async {
|
||||
meCalls += 1;
|
||||
// 缺省给一个「无昵称无头像」的样本(回退到 username 的形态):
|
||||
// 主壳级测试不必逐个注入。
|
||||
return meHandler?.call() ?? Future.value(buildProfile());
|
||||
}
|
||||
|
||||
@override
|
||||
Future<UserProfile> updateMe(UpdateMeRequest request) async {
|
||||
updateMePayloads.add(request.toJson());
|
||||
if (updateMeHandler == null) throw UnimplementedError();
|
||||
return updateMeHandler!(request);
|
||||
}
|
||||
}
|
||||
|
||||
/// `/me` 响应样本(契约 v1.4.0 六字段全字段)。
|
||||
Map<String, dynamic> sampleMeJson({
|
||||
String userId = 'user-1',
|
||||
String username = 'llx',
|
||||
String? nickname,
|
||||
String? avatarUrl,
|
||||
String? phone = '+8613800138000',
|
||||
}) => {
|
||||
'userId': userId,
|
||||
'username': username,
|
||||
'nickname': nickname,
|
||||
'avatarUrl': avatarUrl,
|
||||
'phone': phone,
|
||||
'createdAt': '2026-09-01T10:00:00+08:00',
|
||||
};
|
||||
|
||||
UserProfile buildProfile({
|
||||
String userId = 'user-1',
|
||||
String username = 'llx',
|
||||
String? nickname,
|
||||
String? avatarUrl,
|
||||
}) => UserProfile.fromJson(
|
||||
sampleMeJson(
|
||||
userId: userId,
|
||||
username: username,
|
||||
nickname: nickname,
|
||||
avatarUrl: avatarUrl,
|
||||
),
|
||||
);
|
||||
|
||||
/// mock dio:用假 HttpClientAdapter 返回预设响应并记录请求。
|
||||
class FakeHttpAdapter implements HttpClientAdapter {
|
||||
FakeHttpAdapter(this.handler);
|
||||
|
||||
@@ -201,6 +201,7 @@ class FakeCommunityRepository implements CommunityRepository {
|
||||
Future<void> Function(String commentId)? onDeleteComment;
|
||||
Future<FollowState> Function(String userId, bool target)? onFollowToggle;
|
||||
Future<FollowStats> Function(String userId)? onGetFollowStats;
|
||||
Future<CommunityStats> Function()? onGetMyCommunityStats;
|
||||
Future<MediaUploadCredentials> Function(CreateMediaUploadRequest request)?
|
||||
onCreateMediaUpload;
|
||||
Future<MediaAsset> Function(String assetId)? onCompleteMediaUpload;
|
||||
@@ -213,6 +214,9 @@ class FakeCommunityRepository implements CommunityRepository {
|
||||
/// createPost 收到的幂等键顺序(同键重放断言用)。
|
||||
final List<String?> idempotencyKeys = [];
|
||||
|
||||
/// 最近一次 createMediaUpload 的请求(purpose 断言用)。
|
||||
CreateMediaUploadRequest? lastMediaUploadRequest;
|
||||
|
||||
@override
|
||||
Future<CursorPage<FeedCard>> getFeed({int? limit, String? cursor}) {
|
||||
calls.add('feed:cursor=$cursor');
|
||||
@@ -254,6 +258,7 @@ class FakeCommunityRepository implements CommunityRepository {
|
||||
CreateMediaUploadRequest request,
|
||||
) {
|
||||
calls.add('createUpload:${request.mimeType}:${request.byteSize}');
|
||||
lastMediaUploadRequest = request;
|
||||
return onCreateMediaUpload!(request);
|
||||
}
|
||||
|
||||
@@ -338,10 +343,44 @@ class FakeCommunityRepository implements CommunityRepository {
|
||||
@override
|
||||
Future<FollowStats> getFollowStats(String userId) {
|
||||
calls.add('followStats:$userId');
|
||||
return onGetFollowStats!(userId);
|
||||
return onGetFollowStats?.call(userId) ??
|
||||
Future.value(FollowStats.fromJson(sampleFollowStatsJson()));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<CommunityStats> getMyCommunityStats() {
|
||||
calls.add('communityStats');
|
||||
return onGetMyCommunityStats?.call() ??
|
||||
// 缺省零值(契约:空数据返回 0 而非 null,且永不 404)。
|
||||
Future.value(
|
||||
CommunityStats.fromJson(
|
||||
sampleCommunityStatsJson(
|
||||
receivedLikeCount: 0,
|
||||
publishedPostCount: 0,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<CursorPage<FeedCard>> listMyBookmarks({int? limit, String? cursor}) =>
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
Map<String, dynamic> sampleCommunityStatsJson({
|
||||
int receivedLikeCount = 128,
|
||||
int publishedPostCount = 12,
|
||||
}) => {
|
||||
'receivedLikeCount': receivedLikeCount,
|
||||
'publishedPostCount': publishedPostCount,
|
||||
};
|
||||
|
||||
Map<String, dynamic> sampleFollowStatsJson({
|
||||
int followerCount = 24,
|
||||
int followingCount = 7,
|
||||
bool followedByMe = false,
|
||||
}) => {
|
||||
'followerCount': followerCount,
|
||||
'followingCount': followingCount,
|
||||
'followedByMe': followedByMe,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user