所有一级页面和不分二级页面
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
import '../../../../../../core/error/failure.dart';
|
||||
import '../models/report_model.dart';
|
||||
|
||||
/// 上报远程数据源接口
|
||||
abstract class ReportRemoteDataSource {
|
||||
/// 提交上报数据
|
||||
Future<Either<Failure, bool>> submitReport(ReportModel report);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
import '../../../../../../core/error/failure.dart';
|
||||
import '../models/report_model.dart';
|
||||
import 'report_remote_datasource.dart';
|
||||
|
||||
/// 上报远程数据源实现(模拟接口请求)
|
||||
class ReportRemoteDataSourceImpl implements ReportRemoteDataSource {
|
||||
@override
|
||||
Future<Either<Failure, bool>> submitReport(ReportModel report) async {
|
||||
// 模拟网络请求延迟
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
|
||||
// 模拟成功返回
|
||||
return right(true);
|
||||
|
||||
// 模拟失败情况(取消注释以测试错误处理)
|
||||
// return left(ServerFailure('提交失败,请重试'));
|
||||
}
|
||||
}
|
||||
68
lib/features/v2/report/data/models/report_model.dart
Normal file
68
lib/features/v2/report/data/models/report_model.dart
Normal file
@@ -0,0 +1,68 @@
|
||||
import '../../domain/entities/report_entity.dart';
|
||||
|
||||
/// 上报数据模型
|
||||
class ReportModel {
|
||||
final String? location;
|
||||
final String? reportType;
|
||||
final String? deviceId;
|
||||
final String? description;
|
||||
final List<String>? mediaUrls;
|
||||
final String? problemLevel;
|
||||
|
||||
ReportModel({
|
||||
this.location,
|
||||
this.reportType,
|
||||
this.deviceId,
|
||||
this.description,
|
||||
this.mediaUrls,
|
||||
this.problemLevel,
|
||||
});
|
||||
|
||||
/// 从 JSON 创建
|
||||
factory ReportModel.fromJson(Map<String, dynamic> json) {
|
||||
return ReportModel(
|
||||
location: json['location'] as String?,
|
||||
reportType: json['reportType'] as String?,
|
||||
deviceId: json['deviceId'] as String?,
|
||||
description: json['description'] as String?,
|
||||
mediaUrls: (json['mediaUrls'] as List<dynamic>?)?.cast<String>(),
|
||||
problemLevel: json['problemLevel'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
/// 转换为 JSON
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'location': location,
|
||||
'reportType': reportType,
|
||||
'deviceId': deviceId,
|
||||
'description': description,
|
||||
'mediaUrls': mediaUrls,
|
||||
'problemLevel': problemLevel,
|
||||
};
|
||||
}
|
||||
|
||||
/// 转换为实体
|
||||
ReportEntity toEntity() {
|
||||
return ReportEntity(
|
||||
location: location,
|
||||
reportType: reportType,
|
||||
deviceId: deviceId,
|
||||
description: description,
|
||||
mediaUrls: mediaUrls,
|
||||
problemLevel: problemLevel,
|
||||
);
|
||||
}
|
||||
|
||||
/// 从实体创建
|
||||
factory ReportModel.fromEntity(ReportEntity entity) {
|
||||
return ReportModel(
|
||||
location: entity.location,
|
||||
reportType: entity.reportType,
|
||||
deviceId: entity.deviceId,
|
||||
description: entity.description,
|
||||
mediaUrls: entity.mediaUrls,
|
||||
problemLevel: entity.problemLevel,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
import '../../../../../../core/error/failure.dart';
|
||||
import '../../domain/entities/report_entity.dart';
|
||||
import '../../domain/repositories/report_repository.dart';
|
||||
import '../datasources/report_remote_datasource.dart';
|
||||
import '../models/report_model.dart';
|
||||
|
||||
/// 上报仓储实现
|
||||
class ReportRepositoryImpl implements ReportRepository {
|
||||
final ReportRemoteDataSource remoteDataSource;
|
||||
|
||||
ReportRepositoryImpl({required this.remoteDataSource});
|
||||
|
||||
@override
|
||||
Future<Either<Failure, bool>> submitReport(ReportEntity report) async {
|
||||
// 将实体转换为模型
|
||||
final reportModel = ReportModel.fromEntity(report);
|
||||
|
||||
// 调用远程数据源
|
||||
return await remoteDataSource.submitReport(reportModel);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user