diff --git a/lib/data/repositories/floor_plan_repository.dart b/lib/data/repositories/floor_plan_repository.dart index 689b05a..2fea66c 100644 --- a/lib/data/repositories/floor_plan_repository.dart +++ b/lib/data/repositories/floor_plan_repository.dart @@ -1,6 +1,25 @@ -import '../../domain/models/floor_plan.dart'; +import '../../domain/models/floor.dart'; -abstract class FloorPlanRepository { - Future getFloorPlan(); - Future saveFloorPlan(FloorPlan plan); +abstract class FloorRepository { + Future getFirstFloor(); + Future createFloor({required String name}); + Future> getRooms(int floorId); + Future createRoom( + int floorId, { + required String name, + required double width, + required double height, + double x = 0, + double y = 0, + }); + Future updateRoom( + int floorId, + int roomId, { + String? name, + double? x, + double? y, + double? width, + double? height, + }); + Future deleteRoom(int floorId, int roomId); } diff --git a/lib/data/repositories/phoenix_floor_plan_repository.dart b/lib/data/repositories/phoenix_floor_plan_repository.dart index 8ae61df..9c52429 100644 --- a/lib/data/repositories/phoenix_floor_plan_repository.dart +++ b/lib/data/repositories/phoenix_floor_plan_repository.dart @@ -1,15 +1,71 @@ -import '../../domain/models/floor_plan.dart'; +import '../../domain/models/floor.dart'; import '../sources/localiser/floor_client.dart'; import 'floor_plan_repository.dart'; -class PhoenixFloorPlanRepository implements FloorPlanRepository { +class PhoenixFloorPlanRepository implements FloorRepository { const PhoenixFloorPlanRepository({required this.client}); final FloorClient client; @override - Future getFloorPlan() => throw UnimplementedError(); + Future getFirstFloor() async { + final list = await client.getFloors(); + if (list.isEmpty) return null; + return Floor.fromJson(list.first as Map); + } @override - Future saveFloorPlan(FloorPlan plan) => throw UnimplementedError(); + Future createFloor({required String name}) async { + final json = await client.createFloor({'name': name}); + return Floor.fromJson(json); + } + + @override + Future> getRooms(int floorId) async { + final list = await client.getRooms(floorId); + return list.map((r) => Room.fromJson(r as Map)).toList(); + } + + @override + Future 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 updateRoom( + int floorId, + int roomId, { + String? name, + double? x, + double? y, + double? width, + double? height, + }) async { + final params = {}; + 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 deleteRoom(int floorId, int roomId) => + client.deleteRoom(floorId, roomId); }