业务更新User所需(企业成员、聊天室群组成员)
This commit is contained in:
56
apps/im_app/lib/domain/repositories/call_log_repository.dart
Normal file
56
apps/im_app/lib/domain/repositories/call_log_repository.dart
Normal file
@@ -0,0 +1,56 @@
|
||||
import 'package:im_app/domain/entities/call_log.dart';
|
||||
|
||||
/// 通话记录仓储接口
|
||||
///
|
||||
/// ## 职责
|
||||
/// - StorageSdkApi ↔ Domain CallLog 映射
|
||||
/// - CRUD 操作(通过 StorageSdkApi,不直接接触 DB)
|
||||
/// - 所有公开接口只接受 Domain 实体,Companion 转换完全内聚在 Impl
|
||||
///
|
||||
/// ## 数据流
|
||||
/// ```
|
||||
/// 写入:Domain CallLog → _toCompanion() → StorageSdkApi → DB
|
||||
/// 读取:DB row (DriftCallLog) → _toEntity() → Domain CallLog
|
||||
/// 监听:DB 变化 → stream → Domain CallLog → UI
|
||||
/// ```
|
||||
abstract class CallLogRepository {
|
||||
// ── 监听 ─────────────────────────────────────────────────────────────────
|
||||
|
||||
/// 监听所有通话记录,DB 变化自动反映
|
||||
Stream<List<CallLog>> watchAllCallLogs();
|
||||
|
||||
/// 监听指定通话记录
|
||||
Stream<CallLog?> watchCallLog(String id);
|
||||
|
||||
// ── 读取 ─────────────────────────────────────────────────────────────────
|
||||
|
||||
/// 读取所有通话记录,按 updated_at 降序
|
||||
Future<List<CallLog>> getCallLogs();
|
||||
|
||||
/// 读取指定通话记录,不存在返回 null
|
||||
Future<CallLog?> getCallLog(String id);
|
||||
|
||||
/// 检查通话记录是否存在
|
||||
Future<bool> isExist(String id);
|
||||
|
||||
/// 获取未读通话数量
|
||||
///
|
||||
/// 统计 is_read = 0 且非主叫的未接/取消/结束/超时通话
|
||||
Future<int> getUnreadCount(int currentUid);
|
||||
|
||||
// ── 写入 ─────────────────────────────────────────────────────────────────
|
||||
|
||||
/// 插入或替换通话记录
|
||||
Future<void> insertOrReplaceCallLog(CallLog callLog);
|
||||
|
||||
/// 批量插入或替换通话记录
|
||||
Future<void> insertOrReplaceCallLogs(List<CallLog> callLogs);
|
||||
|
||||
/// 将所有通话记录标记为已读
|
||||
Future<void> markAllAsRead();
|
||||
|
||||
// ── 删除 ─────────────────────────────────────────────────────────────────
|
||||
|
||||
/// 删除指定通话记录
|
||||
Future<void> deleteCallLog(String id);
|
||||
}
|
||||
53
apps/im_app/lib/domain/repositories/chat_bot_repository.dart
Normal file
53
apps/im_app/lib/domain/repositories/chat_bot_repository.dart
Normal file
@@ -0,0 +1,53 @@
|
||||
import 'package:im_app/domain/entities/chat_bot.dart';
|
||||
|
||||
/// 聊天机器人仓储接口
|
||||
///
|
||||
/// ## 职责
|
||||
/// - StorageSdkApi ↔ Domain ChatBot 映射
|
||||
/// - CRUD 操作(通过 StorageSdkApi,不直接接触 DB)
|
||||
/// - 所有公开接口只接受 Domain 实体,Companion 转换完全内聚在 Impl
|
||||
///
|
||||
/// ## 数据流
|
||||
/// ```
|
||||
/// 写入:Domain ChatBot → _toCompanion() → StorageSdkApi → DB
|
||||
/// 读取:DB row (DriftChatBot) → _toEntity() → Domain ChatBot
|
||||
/// 监听:DB 变化 → stream → Domain ChatBot → UI
|
||||
/// ```
|
||||
abstract class ChatBotRepository {
|
||||
// ── 监听 ─────────────────────────────────────────────────────────────────
|
||||
|
||||
/// 监听所有聊天机器人,DB 变化自动反映
|
||||
Stream<List<ChatBot>> watchAllChatBots();
|
||||
|
||||
/// 监听指定聊天机器人
|
||||
Stream<ChatBot?> watchChatBot(int id);
|
||||
|
||||
// ── 读取 ─────────────────────────────────────────────────────────────────
|
||||
|
||||
/// 读取所有聊天机器人
|
||||
///
|
||||
/// [limit] 可选限制数量
|
||||
Future<List<ChatBot>> getChatBots({int? limit});
|
||||
|
||||
/// 读取指定聊天机器人,不存在返回 null
|
||||
Future<ChatBot?> getChatBot(int id);
|
||||
|
||||
// ── 写入 ─────────────────────────────────────────────────────────────────
|
||||
|
||||
/// 插入或替换聊天机器人
|
||||
Future<void> insertOrReplaceChatBot(ChatBot chatBot);
|
||||
|
||||
/// 批量插入或替换聊天机器人
|
||||
Future<void> insertOrReplaceChatBots(List<ChatBot> chatBots);
|
||||
|
||||
/// 更新聊天机器人
|
||||
Future<void> updateChatBot(ChatBot chatBot);
|
||||
|
||||
// ── 删除 ─────────────────────────────────────────────────────────────────
|
||||
|
||||
/// 删除指定聊天机器人
|
||||
Future<void> deleteChatBot(int id);
|
||||
|
||||
/// 清空所有聊天机器人
|
||||
Future<void> clearChatBots();
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:im_app/data/local/drift/app_database.dart';
|
||||
import 'package:im_app/domain/entities/user.dart';
|
||||
|
||||
/// 用户仓储接口
|
||||
@@ -7,6 +6,7 @@ import 'package:im_app/domain/entities/user.dart';
|
||||
/// - StorageSdkApi ↔ Domain User 映射
|
||||
/// - CRUD 操作(通过 StorageSdkApi,不直接接触 DB)
|
||||
/// - 实时监听(单个 / 多个 / 全部)
|
||||
/// - 所有公开接口只接受 Domain 实体,Companion 转换完全内聚在 Impl
|
||||
///
|
||||
/// ## 数据流
|
||||
/// ```
|
||||
@@ -53,23 +53,34 @@ abstract class UserRepository {
|
||||
|
||||
// ── 写入 ─────────────────────────────────────────────────────────────────
|
||||
|
||||
/// 保存完整用户(insert or replace)
|
||||
/// 调用方决定是否持久化
|
||||
Future<void> saveUser(User user);
|
||||
/// 插入或替换单个用户
|
||||
Future<void> insertOrReplaceUser(User user);
|
||||
|
||||
/// 批量保存用户(insert or replace)
|
||||
Future<void> saveUsers(List<User> users);
|
||||
/// 批量插入或替换用户
|
||||
Future<void> insertOrReplaceUsers(List<User> users);
|
||||
|
||||
/// 仅更新指定字段,不影响其他列
|
||||
/// 更新单个用户所有字段,按 uid 匹配
|
||||
///
|
||||
/// 示例:
|
||||
/// ```dart
|
||||
/// await repo.updateFields(uid, UsersCompanion(
|
||||
/// nickname: Value('New Name'),
|
||||
/// lastOnline: Value(DateTime.now().millisecondsSinceEpoch),
|
||||
/// ));
|
||||
/// await repo.updateUser(user.copyWith(nickname: 'New Name'));
|
||||
/// ```
|
||||
Future<void> updateFields(int uid, UsersCompanion companion);
|
||||
Future<void> updateUser(User user);
|
||||
|
||||
/// 批量更新用户,每条按 uid 匹配更新所有字段
|
||||
///
|
||||
/// 示例:
|
||||
/// ```dart
|
||||
/// final updated = users.map((u) => u.copyWith(nickname: 'new')).toList();
|
||||
/// await repo.updateUsersBatch(updated);
|
||||
/// ```
|
||||
Future<void> updateUsersBatch(List<User> users);
|
||||
|
||||
/// 单条 upsert
|
||||
Future<void> upsertUser(User user);
|
||||
|
||||
/// 批量 upsert,走单次事务,优于循环调用 [upsertUser]
|
||||
Future<void> upsertUsers(List<User> users);
|
||||
|
||||
// ── 删除 ─────────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
Reference in New Issue
Block a user