路及规划-集成(打点绘制)后端接口
This commit is contained in:
@@ -23,8 +23,11 @@ import '../../features/auth/presentation/bloc/login_cubit.dart';
|
||||
import '../../features/devices/data/datasources/device_http_datasource.dart';
|
||||
import '../../features/devices/data/repositories/device_hostriry_work_impl.dart';
|
||||
import '../../features/devices/data/repositories/device_repository_impl.dart';
|
||||
import '../../features/devices/data/repositories/generate_path_repository_Impl.dart';
|
||||
import '../../features/devices/domain/repositories/device_hostrity_work_repository.dart';
|
||||
import '../../features/devices/domain/repositories/path_repository.dart';
|
||||
import '../../features/devices/domain/usecases/device_work_hostrirty_usecase.dart';
|
||||
import '../../features/devices/domain/usecases/generate_path_usecase.dart';
|
||||
import '../../features/devices/domain/usecases/get_device_location_usecase.dart';
|
||||
import '../../features/remote_control/presentation/bloc/remote_control_cubit.dart';
|
||||
import '../app/app_user_cubit.dart';
|
||||
@@ -107,6 +110,15 @@ Future<void> init() async {
|
||||
sl.registerLazySingleton(() => DevicesCubit(sl(), sl(), sl()));
|
||||
sl.registerFactory(() => RemoteControlCubit(sl()));
|
||||
|
||||
|
||||
|
||||
/// . 路径生成
|
||||
sl.registerLazySingleton<PathRepository>(() => PathRepositoryImpl());
|
||||
sl.registerLazySingleton<GeneratePathUseCase>(
|
||||
() => GeneratePathUseCaseImpl(sl<PathRepository>()),
|
||||
);
|
||||
|
||||
|
||||
/// 6. 认证 (Auth)
|
||||
// --- 关键修改点 1: AuthCubit 必须在 GoRouter 之前注册,并传入参数 ---
|
||||
sl.registerLazySingleton(
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
class DeviceAddPathPointModel {
|
||||
final double latitude;
|
||||
final double longitude;
|
||||
|
||||
DeviceAddPathPointModel({required this.latitude, required this.longitude});
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'latitude': latitude,
|
||||
'longitude': longitude,
|
||||
};
|
||||
|
||||
factory DeviceAddPathPointModel.fromJson(Map<String, dynamic> json) => DeviceAddPathPointModel(
|
||||
latitude: json['latitude'],
|
||||
longitude: json['longitude'],
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'dart:convert';
|
||||
|
||||
import '../../domain/repositories/path_repository.dart';
|
||||
import '../models/device_add_path_point_model.dart';
|
||||
|
||||
class PathRepositoryImpl implements PathRepository {
|
||||
final String baseUrl = 'https://your-backend-api.com'; // 后端接口地址
|
||||
// 生成路径
|
||||
@override
|
||||
Future<List<DeviceAddPathPointModel>> generatePath(List<DeviceAddPathPointModel> coordinates) async {
|
||||
final url = Uri.parse('$baseUrl/api/path');
|
||||
final headers = {'Content-Type': 'application/json'};
|
||||
final body = jsonEncode({
|
||||
'coordinates': coordinates.map((p) => p.toJson()).toList(),
|
||||
});
|
||||
|
||||
try {
|
||||
final response = await http.post(url, headers: headers, body: body);
|
||||
if (response.statusCode == 200) {
|
||||
final List<dynamic> jsonData = jsonDecode(response.body)['path'];
|
||||
return jsonData.map((item) => DeviceAddPathPointModel.fromJson(item)).toList();
|
||||
} else {
|
||||
throw Exception('Failed to load path: ${response.statusCode}');
|
||||
}
|
||||
} catch (e) {
|
||||
throw Exception('Network error: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import '../../data/models/device_add_path_point_model.dart';
|
||||
|
||||
abstract class PathRepository {
|
||||
// Generate path(打点生成路径规划)
|
||||
Future<List<DeviceAddPathPointModel>> generatePath(List<DeviceAddPathPointModel> coordinates);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import '../../data/models/device_add_path_point_model.dart';
|
||||
import '../repositories/path_repository.dart';
|
||||
|
||||
abstract class GeneratePathUseCase {
|
||||
Future<List<DeviceAddPathPointModel>> execute(List<DeviceAddPathPointModel> coordinates);
|
||||
}
|
||||
|
||||
class GeneratePathUseCaseImpl implements GeneratePathUseCase {
|
||||
final PathRepository _repository;
|
||||
|
||||
GeneratePathUseCaseImpl(this._repository);
|
||||
|
||||
@override
|
||||
Future<List<DeviceAddPathPointModel>> execute(List<DeviceAddPathPointModel> coordinates) async {
|
||||
return await _repository.generatePath(coordinates);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user