feat: 后端架构重构 — Endpoint→Service→Repository分层 + AI确认机制 + 异步任务持久化
- 核心业务拆分为 Endpoint → Application Service → Repository 三层 - AI写入操作必须用户确认后才写库(确认卡片机制) - 报告/饮食/用药分析改为持久化任务队列(原子领取/重试/重启恢复) - 运动计划修复: 连续真实日期替代周模板 - 用药提醒去重 + 通知Outbox预留 - 认证收拢到AuthService, 管理员收拢到AdminService - AI会话加用户归属校验防串号 - 提示词调整为患者视角 - 开发假数据已关闭 - 21/21测试通过, 0警告0错误
This commit is contained in:
43
health_app/lib/services/in_app_notification_service.dart
Normal file
43
health_app/lib/services/in_app_notification_service.dart
Normal file
@@ -0,0 +1,43 @@
|
||||
import '../core/api_client.dart';
|
||||
|
||||
class InAppNotification {
|
||||
final String id;
|
||||
final String type;
|
||||
final String title;
|
||||
final String message;
|
||||
|
||||
const InAppNotification({
|
||||
required this.id,
|
||||
required this.type,
|
||||
required this.title,
|
||||
required this.message,
|
||||
});
|
||||
|
||||
factory InAppNotification.fromJson(Map<String, dynamic> json) =>
|
||||
InAppNotification(
|
||||
id: json['id']?.toString() ?? '',
|
||||
type: json['type']?.toString() ?? '',
|
||||
title: json['title']?.toString() ?? '健康提醒',
|
||||
message: json['message']?.toString() ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
class InAppNotificationService {
|
||||
final ApiClient _api;
|
||||
|
||||
const InAppNotificationService(this._api);
|
||||
|
||||
Future<List<InAppNotification>> getPending() async {
|
||||
final response = await _api.get('/api/notifications/pending');
|
||||
final items = response.data['data'] as List? ?? const [];
|
||||
return items
|
||||
.whereType<Map>()
|
||||
.map((item) => InAppNotification.fromJson(Map<String, dynamic>.from(item)))
|
||||
.where((item) => item.id.isNotEmpty)
|
||||
.toList();
|
||||
}
|
||||
|
||||
Future<void> acknowledge(String id) async {
|
||||
await _api.post('/api/notifications/$id/acknowledge');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user