已完成用户APP首期功能开发
交付用户端首期页面、配套接口、后台资源及测试文档。用户APP构建、静态分析和三个管理后台构建通过;完整测试仍有2项失败,后端模型注释检查未通过,详见交付记录。
This commit is contained in:
File diff suppressed because it is too large
Load Diff
54
apps/user_app/lib/data/repositories/primary_repository.dart
Normal file
54
apps/user_app/lib/data/repositories/primary_repository.dart
Normal file
@@ -0,0 +1,54 @@
|
||||
// 功能描述:将兼容仓储响应转换为一级页面领域模型,隔离通用记录。
|
||||
// 版本:1.0.0
|
||||
import '../../domain/models/primary_models.dart';
|
||||
import '../services/api_client.dart';
|
||||
import 'client_repository.dart';
|
||||
|
||||
/// 首页与商城的兼容迁移适配器;旧 Repository 接口继续保留。
|
||||
class PrimaryRepository {
|
||||
const PrimaryRepository(this.client);
|
||||
final ClientRepository client;
|
||||
|
||||
/// 返回已发布内容;旧接口缺少正文时保留空值,不拼造内容。
|
||||
Future<List<PublishedContent>> contents() async => (await client.contents())
|
||||
.map(
|
||||
(r) => PublishedContent(
|
||||
identity: r.identity,
|
||||
title: r.title,
|
||||
body: r.raw['body'] as String? ?? '',
|
||||
type: r.raw['content_type'] as String? ?? '',
|
||||
version: r.raw['version_no'] as int? ?? 1,
|
||||
publishedAt: DateTime.tryParse(r.raw['created_at'] as String? ?? ''),
|
||||
),
|
||||
)
|
||||
.toList(growable: false);
|
||||
|
||||
/// 返回服务归属,空响应表示尚未建立服务关系。
|
||||
Future<ServiceRelation?> relation() async {
|
||||
final data = await client.serviceRelation();
|
||||
if (data == null) return null;
|
||||
return ServiceRelation(
|
||||
gasName: data['gas_name'] as String? ?? '',
|
||||
deliveryName: data['delivery_name'] as String? ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
/// 严格检查金额、库存类型,避免把畸形价格显示为零元。
|
||||
Future<List<ProductSummary>> products() async => (await client.products())
|
||||
.map((r) {
|
||||
final price = r.raw['price_amount'];
|
||||
final stock = r.raw['stock_quantity'];
|
||||
if (price is! int || price < 0 || stock is! int || stock < 0) {
|
||||
throw const ApiException(1714, '商品数据异常,请刷新后重试');
|
||||
}
|
||||
return ProductSummary(
|
||||
identity: r.identity,
|
||||
name: r.title,
|
||||
price: price,
|
||||
stock: stock,
|
||||
category: r.raw['category_name'] as String? ?? '',
|
||||
imageUrl: client.resolveImageUrl(r.raw['image_url'] as String? ?? ''),
|
||||
);
|
||||
})
|
||||
.toList(growable: false);
|
||||
}
|
||||
Reference in New Issue
Block a user