业务更新User所需(企业成员、聊天室群组成员)
This commit is contained in:
@@ -87,7 +87,7 @@ class ChatDbTestViewModel extends _$ChatDbTestViewModel {
|
||||
_loadNextPage();
|
||||
}
|
||||
|
||||
// ── 测试 ──────────────────────────────────────────────────────────────────
|
||||
// ── 测试:插入 ────────────────────────────────────────────────────────────
|
||||
|
||||
void startDBTest(BuildContext context) {
|
||||
_isTesting = true;
|
||||
@@ -147,4 +147,67 @@ class ChatDbTestViewModel extends _$ChatDbTestViewModel {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ── 测试:更新 ────────────────────────────────────────────────────────────
|
||||
|
||||
void updateFirst10(BuildContext context) {
|
||||
_testDBUpdate();
|
||||
}
|
||||
|
||||
Future<void> _testDBUpdate() async {
|
||||
final useCase = ref.read(updateUsersUseCaseProvider);
|
||||
final users = state.users;
|
||||
|
||||
if (users.isEmpty) {
|
||||
state = state.copyWith(currentState: '暂无数据,请先插入');
|
||||
return;
|
||||
}
|
||||
|
||||
final updated = await useCase.execute(users);
|
||||
|
||||
if (ref.mounted) {
|
||||
final updatedMap = {for (final u in updated) u.uid: u};
|
||||
final updatedList = state.users
|
||||
.map((u) => updatedMap[u.uid] ?? u)
|
||||
.toList();
|
||||
|
||||
state = state.copyWith(
|
||||
users: updatedList,
|
||||
currentState: '已更新前 ${updated.length} 条',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ── 测试:删除 ────────────────────────────────────────────────────────────
|
||||
|
||||
void deleteFirst10(BuildContext context) {
|
||||
_testDBDelete();
|
||||
}
|
||||
|
||||
Future<void> _testDBDelete() async {
|
||||
final useCase = ref.read(deleteUsersUseCaseProvider);
|
||||
final repo = ref.read(userRepositoryProvider);
|
||||
final users = state.users;
|
||||
|
||||
if (users.isEmpty) {
|
||||
state = state.copyWith(currentState: '暂无数据,请先插入');
|
||||
return;
|
||||
}
|
||||
|
||||
final deleted = await useCase.execute(users);
|
||||
|
||||
if (ref.mounted) {
|
||||
final deletedUids = {for (final u in deleted) u.uid};
|
||||
final updatedList = state.users
|
||||
.where((u) => !deletedUids.contains(u.uid))
|
||||
.toList();
|
||||
|
||||
final total = await repo.countUsers();
|
||||
state = state.copyWith(
|
||||
users: updatedList,
|
||||
totalCount: total,
|
||||
currentState: '已删除前 ${deleted.length} 条',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user