feat: extend Floor repository, implement a Phoenix repo

This commit is contained in:
2026-05-12 16:36:36 +02:00
parent fd0eaa1ddf
commit 0cc4a337a9
2 changed files with 83 additions and 8 deletions
@@ -1,6 +1,25 @@
import '../../domain/models/floor_plan.dart';
import '../../domain/models/floor.dart';
abstract class FloorPlanRepository {
Future<FloorPlan?> getFloorPlan();
Future<FloorPlan> saveFloorPlan(FloorPlan plan);
abstract class FloorRepository {
Future<Floor?> getFirstFloor();
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 'floor_plan_repository.dart';
class PhoenixFloorPlanRepository implements FloorPlanRepository {
class PhoenixFloorPlanRepository implements FloorRepository {
const PhoenixFloorPlanRepository({required this.client});
final FloorClient client;
@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
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);
}