分区相关
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
import '../../../../core/error/failure.dart';
|
||||
import '../../../autonomous_work/domain/repositories/autonomous_work_gateway.dart';
|
||||
import '../../domain/entities/region_draft.dart';
|
||||
import '../../domain/repositories/region_repository.dart';
|
||||
import '../datasources/region_remote_datasource.dart';
|
||||
|
||||
class RegionRepositoryImpl implements RegionRepository {
|
||||
RegionRepositoryImpl({required this.remote, required this.routes});
|
||||
final RegionRemoteDatasource remote;
|
||||
final AutonomousWorkGateway routes;
|
||||
|
||||
@override
|
||||
Future<Either<Failure, List<RegionDraft>>> loadRegions(int siteId) async {
|
||||
try {
|
||||
return Right(await remote.loadRegions(siteId));
|
||||
} catch (error) {
|
||||
return Left(Failure(error.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<Failure, bool>> deleteRegions(List<int> ids) async {
|
||||
try {
|
||||
return Right(await remote.deleteRegions(ids));
|
||||
} catch (error) {
|
||||
return Left(Failure(error.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<Failure, RegionSaveResult>> save(RegionDraft draft) async {
|
||||
try {
|
||||
return Right(await remote.save(draft));
|
||||
} catch (error) {
|
||||
return Left(Failure(error.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<Failure, List<RegionRouteOption>>> loadRoutes(
|
||||
int siteId,
|
||||
) async {
|
||||
try {
|
||||
final result = await routes.loadRoutes(siteId: siteId);
|
||||
if (!result.isOk) return Left(Failure(result.error ?? '路线加载失败'));
|
||||
final options = <int, RegionRouteOption>{};
|
||||
for (final route in result.data ?? []) {
|
||||
final id = int.tryParse(route.id);
|
||||
if (id != null && id > 0) {
|
||||
options[id] = RegionRouteOption(id: id, name: route.name);
|
||||
}
|
||||
}
|
||||
return Right(options.values.toList());
|
||||
} catch (error) {
|
||||
return Left(Failure(error.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user