feat: extend Floor repository, implement a Phoenix repo
This commit is contained in:
@@ -1,6 +1,25 @@
|
|||||||
import '../../domain/models/floor_plan.dart';
|
import '../../domain/models/floor.dart';
|
||||||
|
|
||||||
abstract class FloorPlanRepository {
|
abstract class FloorRepository {
|
||||||
Future<FloorPlan?> getFloorPlan();
|
Future<Floor?> getFirstFloor();
|
||||||
Future<FloorPlan> saveFloorPlan(FloorPlan plan);
|
Future<Floor> createFloor({required String name});
|
||||||
|
Future<List<Room>> getRooms(int floorId);
|
||||||
|
Future<Room> createRoom(
|
||||||
|
int floorId, {
|
||||||
|
required String name,
|
||||||
|
required double width,
|
||||||
|
required double height,
|
||||||
|
double x = 0,
|
||||||
|
double y = 0,
|
||||||
|
});
|
||||||
|
Future<Room> updateRoom(
|
||||||
|
int floorId,
|
||||||
|
int roomId, {
|
||||||
|
String? name,
|
||||||
|
double? x,
|
||||||
|
double? y,
|
||||||
|
double? width,
|
||||||
|
double? height,
|
||||||
|
});
|
||||||
|
Future<void> deleteRoom(int floorId, int roomId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,71 @@
|
|||||||
import '../../domain/models/floor_plan.dart';
|
import '../../domain/models/floor.dart';
|
||||||
import '../sources/localiser/floor_client.dart';
|
import '../sources/localiser/floor_client.dart';
|
||||||
import 'floor_plan_repository.dart';
|
import 'floor_plan_repository.dart';
|
||||||
|
|
||||||
class PhoenixFloorPlanRepository implements FloorPlanRepository {
|
class PhoenixFloorPlanRepository implements FloorRepository {
|
||||||
const PhoenixFloorPlanRepository({required this.client});
|
const PhoenixFloorPlanRepository({required this.client});
|
||||||
|
|
||||||
final FloorClient client;
|
final FloorClient client;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<FloorPlan?> getFloorPlan() => throw UnimplementedError();
|
Future<Floor?> getFirstFloor() async {
|
||||||
|
final list = await client.getFloors();
|
||||||
|
if (list.isEmpty) return null;
|
||||||
|
return Floor.fromJson(list.first as Map<String, dynamic>);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<FloorPlan> saveFloorPlan(FloorPlan plan) => throw UnimplementedError();
|
Future<Floor> createFloor({required String name}) async {
|
||||||
|
final json = await client.createFloor({'name': name});
|
||||||
|
return Floor.fromJson(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<List<Room>> getRooms(int floorId) async {
|
||||||
|
final list = await client.getRooms(floorId);
|
||||||
|
return list.map((r) => Room.fromJson(r as Map<String, dynamic>)).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Room> createRoom(
|
||||||
|
int floorId, {
|
||||||
|
required String name,
|
||||||
|
required double width,
|
||||||
|
required double height,
|
||||||
|
double x = 0,
|
||||||
|
double y = 0,
|
||||||
|
}) async {
|
||||||
|
final json = await client.createRoom(floorId, {
|
||||||
|
'name': name,
|
||||||
|
'width': width,
|
||||||
|
'height': height,
|
||||||
|
'x': x,
|
||||||
|
'y': y,
|
||||||
|
});
|
||||||
|
return Room.fromJson(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Room> updateRoom(
|
||||||
|
int floorId,
|
||||||
|
int roomId, {
|
||||||
|
String? name,
|
||||||
|
double? x,
|
||||||
|
double? y,
|
||||||
|
double? width,
|
||||||
|
double? height,
|
||||||
|
}) async {
|
||||||
|
final params = <String, dynamic>{};
|
||||||
|
if (name != null) params['name'] = name;
|
||||||
|
if (x != null) params['x'] = x;
|
||||||
|
if (y != null) params['y'] = y;
|
||||||
|
if (width != null) params['width'] = width;
|
||||||
|
if (height != null) params['height'] = height;
|
||||||
|
final json = await client.updateRoom(floorId, roomId, params);
|
||||||
|
return Room.fromJson(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> deleteRoom(int floorId, int roomId) =>
|
||||||
|
client.deleteRoom(floorId, roomId);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user