diff --git a/lib/features/app_layout/bloc/home_cubit.dart b/lib/features/app_layout/bloc/home_cubit.dart index 62f2dc5..04d2b81 100644 --- a/lib/features/app_layout/bloc/home_cubit.dart +++ b/lib/features/app_layout/bloc/home_cubit.dart @@ -18,9 +18,9 @@ part 'home_state.dart'; class HomeCubit extends Cubit { HomeCubit._() : super(HomeInitial()) { if (selectedSpace == null) { - fetchSpaces().then((value) { + fetchUnitsByUserId().then((value) { if (selectedSpace != null) { - fetchRooms(selectedSpace!); + fetchRoomsByUnitId(selectedSpace!); } }); } @@ -120,10 +120,10 @@ class HomeCubit extends Cubit { } //////////////////////////////////////// API //////////////////////////////////////// - fetchSpaces() async { + fetchUnitsByUserId() async { emitSafe(GetSpacesLoading()); try { - spaces = await SpacesAPI.getSpaces(); + spaces = await SpacesAPI.getUnitsByUserId(); } catch (failure) { emitSafe(GetSpacesError(failure.toString())); return; @@ -132,13 +132,13 @@ class HomeCubit extends Cubit { if (spaces != null && spaces!.isNotEmpty) { selectedSpace = spaces!.first; emitSafe(GetSpacesSuccess(spaces!)); - fetchRooms(selectedSpace!); + // fetchRoomsByUnitId(selectedSpace!); } else { emitSafe(GetSpacesError("No spaces found")); } } - fetchRooms(SpaceModel space) async { + fetchRoomsByUnitId(SpaceModel space) async { emitSafe(GetSpaceRoomsLoading()); try { space.rooms = await SpacesAPI.getRoomsBySpaceId(space.id!); diff --git a/lib/features/app_layout/model/space_model.dart b/lib/features/app_layout/model/space_model.dart index 629a38f..8d7d5b8 100644 --- a/lib/features/app_layout/model/space_model.dart +++ b/lib/features/app_layout/model/space_model.dart @@ -1,11 +1,14 @@ import 'package:syncrow_app/features/devices/model/room_model.dart'; +import 'package:syncrow_app/utils/resource_manager/constants.dart'; class SpaceModel { - final int? id; + final String? id; final String? name; + final SpaceType type; late List? rooms; SpaceModel({ + required this.type, required this.id, required this.name, required this.rooms, @@ -21,8 +24,9 @@ class SpaceModel { factory SpaceModel.fromJson(Map json) { return SpaceModel( - id: int.parse(json['homeId']), - name: json['homeName'], + id: json['uuid'], + name: json['name'], + type: spaceTypesMap[json['type']]!, rooms: [], ); } diff --git a/lib/features/auth/bloc/auth_cubit.dart b/lib/features/auth/bloc/auth_cubit.dart index 4e10a42..c45e708 100644 --- a/lib/features/auth/bloc/auth_cubit.dart +++ b/lib/features/auth/bloc/auth_cubit.dart @@ -46,19 +46,19 @@ class AuthCubit extends Cubit { String? passwordValidator(String? value) { if (value != null) { if (value.isNotEmpty) { - if (value.length >= 6) { - return null; - //TODO uncomment this code when the password validation is needed - // if (RegExp( - // r'^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$') - // .hasMatch(value)) { - // return null; - // } else { - // return 'Password must contain at least one uppercase letter, one lowercase letter, one number and one special character'; - // } - } else { - return 'Password must be at least 6 characters'; - } + // if (value.length >= 6) { + return null; + //TODO uncomment this code when the password validation is needed + // if (RegExp( + // r'^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$') + // .hasMatch(value)) { + // return null; + // } else { + // return 'Password must contain at least one uppercase letter, one lowercase letter, one number and one special character'; + // } + // } else { + // return 'Password must be at least 6 characters'; + // } } else { return 'Please enter your password'; } @@ -106,12 +106,15 @@ class AuthCubit extends Cubit { return; } if (token.accessTokenIsNotEmpty) { + debugPrint('token: ${token.accessToken}'); FlutterSecureStorage storage = const FlutterSecureStorage(); await storage.write( key: Token.loginAccessTokenKey, value: token.accessToken); + const FlutterSecureStorage().write( key: UserModel.userUuidKey, value: Token.decodeToken(token.accessToken)['uuid'].toString()); + user = UserModel.fromToken(token); emailController.clear(); passwordController.clear(); diff --git a/lib/features/auth/model/token.dart b/lib/features/auth/model/token.dart index 0c428a7..7513673 100644 --- a/lib/features/auth/model/token.dart +++ b/lib/features/auth/model/token.dart @@ -4,7 +4,7 @@ import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:syncrow_app/utils/helpers/decode_base64.dart'; class Token { - static const String loginAccessTokenKey = 'access_token'; + static const String loginAccessTokenKey = 'accessToken'; static const String loginRefreshTokenKey = 'refreshToken'; final String accessToken; @@ -56,7 +56,8 @@ class Token { var storage = const FlutterSecureStorage(); storage.write( key: loginAccessTokenKey, value: json[loginAccessTokenKey] ?? ''); - + storage.write( + key: loginRefreshTokenKey, value: json[loginRefreshTokenKey] ?? ''); //create token object ? return Token(json[loginAccessTokenKey] ?? '', json[loginRefreshTokenKey] ?? '', '', 0, 0); diff --git a/lib/features/devices/bloc/devices_cubit.dart b/lib/features/devices/bloc/devices_cubit.dart index 2cd2fbd..4f3f4b4 100644 --- a/lib/features/devices/bloc/devices_cubit.dart +++ b/lib/features/devices/bloc/devices_cubit.dart @@ -25,7 +25,7 @@ part 'devices_state.dart'; class DevicesCubit extends Cubit { DevicesCubit._() : super(DevicesInitial()) { if (HomeCubit.getInstance().selectedSpace != null) { - fetchGroups(HomeCubit.getInstance().selectedSpace!.id!); + // fetchGroups(HomeCubit.getInstance().selectedSpace!.id!); for (var room in HomeCubit.getInstance().selectedSpace!.rooms!) { fetchDevicesByRoomId(room.id!); } @@ -257,7 +257,7 @@ class DevicesCubit extends Cubit { emitSafe(DeviceControlSuccess(code: control.code)); //this delay is to give tuya server time to update the status Future.delayed(const Duration(milliseconds: 400), () { - getDevicesStatues( + fetchDevicesStatues( deviceId, HomeCubit.getInstance() .selectedSpace! @@ -274,7 +274,7 @@ class DevicesCubit extends Cubit { } } - fetchGroups(int spaceId) async { + fetchGroups(String spaceId) async { emitSafe(DevicesCategoriesLoading()); try { allCategories = await DevicesAPI.fetchGroups(spaceId); @@ -289,7 +289,7 @@ class DevicesCubit extends Cubit { } } - fetchDevicesByRoomId(int? roomId) async { + fetchDevicesByRoomId(String? roomId) async { if (roomId == null) return; emitSafe(GetDevicesLoading()); @@ -308,23 +308,26 @@ class DevicesCubit extends Cubit { //get status for each device //TODO get devices status per page via page controller instead of getting all devices status at once - for (var device - in HomeCubit.getInstance().selectedSpace!.rooms![roomIndex].devices!) { - getDevicesStatues(device.id!, roomIndex); + List devices = + HomeCubit.getInstance().selectedSpace!.rooms![roomIndex].devices!; + if (devices.isNotEmpty) { + for (var device in devices) { + fetchDevicesStatues(device.uuid!, roomIndex); + } } } - getDevicesStatues(String deviceId, int roomIndex, {String? code}) async { + fetchDevicesStatues(String deviceUuid, int roomIndex, {String? code}) async { emitSafe(GetDeviceStatusLoading(code: code)); int deviceIndex = HomeCubit.getInstance() .selectedSpace! .rooms![roomIndex] .devices! - .indexWhere((element) => element.id == deviceId); + .indexWhere((element) => element.uuid == deviceUuid); List statuses = []; try { - var response = await DevicesAPI.getDeviceStatus(deviceId); - for (var status in response['result']['status']) { + var response = await DevicesAPI.getDeviceStatus(deviceUuid); + for (var status in response['status']) { statuses.add(StatusModel.fromJson(status)); } } catch (e) { diff --git a/lib/features/devices/model/device_control_model.dart b/lib/features/devices/model/device_control_model.dart index 58a6476..c2a66e2 100644 --- a/lib/features/devices/model/device_control_model.dart +++ b/lib/features/devices/model/device_control_model.dart @@ -10,8 +10,9 @@ class DeviceControlModel { }); factory DeviceControlModel.fromJson(Map json) { + print('json: $json'); return DeviceControlModel( - deviceId: json['deviceId'], + deviceId: json['deviceUuid'], code: json['code'], value: json['value'], ); @@ -19,7 +20,7 @@ class DeviceControlModel { Map toJson() { return { - 'deviceId': deviceId, + 'deviceUuid': deviceId, 'code': code, 'value': value, }; diff --git a/lib/features/devices/model/device_model.dart b/lib/features/devices/model/device_model.dart index 410fd15..4cd6417 100644 --- a/lib/features/devices/model/device_model.dart +++ b/lib/features/devices/model/device_model.dart @@ -5,25 +5,14 @@ import 'package:syncrow_app/utils/resource_manager/constants.dart'; class DeviceModel { int? activeTime; - String? category; //unused - String? categoryName; //unused - int? createTime; //unused - String? gatewayId; //unused - String? icon; //unused - String? id; - String? ip; //unused - double? lat; //unused + // String? id; String? localKey; - double? lon; //unused String? model; String? name; - String? nodeId; //remove + String? icon; bool? isOnline; List status = []; - String? ownerId; //unused - String? productId; //unused String? productName; - bool? isSub; //unused String? timeZone; int? updateTime; String? uuid; @@ -32,108 +21,70 @@ class DeviceModel { late List functions; DeviceModel({ this.activeTime, - this.category, - this.categoryName, - this.createTime, - this.gatewayId, - this.icon, - this.id, - this.ip, - this.lat, + // this.id, this.localKey, - this.lon, this.model, this.name, - this.nodeId, this.isOnline, required this.status, - this.ownerId, - this.productId, this.productName, - this.isSub, this.timeZone, this.updateTime, this.uuid, this.productType, + this.icon, }) { functions = getFunctions(productType!); } factory DeviceModel.fromJson(Map json) { - String icon = ''; - DeviceType type = devicesTypesMap[json['productId']] ?? DeviceType.Other; + String tempIcon = ''; + DeviceType type = devicesTypesMap[json['productType']] ?? DeviceType.Other; if (type == DeviceType.LightBulb) { - icon = Assets.iconsLight; + tempIcon = Assets.iconsLight; } else if (type == DeviceType.CeilingSensor || type == DeviceType.WallSensor) { - icon = Assets.iconsSensors; + tempIcon = Assets.iconsSensors; } else if (type == DeviceType.AC) { - icon = Assets.iconsAC; + tempIcon = Assets.iconsAC; } else if (type == DeviceType.DoorLock) { - icon = Assets.iconsDoorLock; + tempIcon = Assets.iconsDoorLock; } else if (type == DeviceType.Curtain) { - icon = Assets.iconsCurtain; + tempIcon = Assets.iconsCurtain; } else if (type == DeviceType.ThreeGang) { - icon = Assets.icons3GangSwitch; + tempIcon = Assets.icons3GangSwitch; } else if (type == DeviceType.Gateway) { - icon = Assets.iconsGateway; + tempIcon = Assets.iconsGateway; } else { - icon = Assets.iconsLogo; + tempIcon = Assets.iconsLogo; } return DeviceModel( + icon: tempIcon, activeTime: json['activeTime'], - category: json['category'], - categoryName: json['categoryName'], - createTime: json['createTime'], - gatewayId: json['gatewayId'], - icon: icon, - id: json['id'], - ip: json['ip'], - lat: double.tryParse(json['lat']), + // id: json['id'], localKey: json['localKey'], - lon: double.tryParse(json['lon']), model: json['model'], name: json['name'], - nodeId: json['nodeId'], isOnline: json['online'], - ownerId: json['ownerId'], - productId: json['productId'], productName: json['productName'], - isSub: json['sub'], timeZone: json['timeZone'], updateTime: json['updateTime'], uuid: json['uuid'], productType: type, status: [], - // json['status'] - // .map((e) => StatusModel.fromJson(e)) - // .toList(), - // devicesTypesMap[json['productName']] ?? DeviceType.Other, ); } Map toJson() { return { 'activeTime': activeTime, - 'category': category, - 'categoryName': categoryName, - 'createTime': createTime, - 'gatewayId': gatewayId, - 'icon': icon, - 'id': id, - 'ip': ip, - 'lat': lat, + // 'id': id, 'localKey': localKey, - 'lon': lon, 'model': model, 'name': name, - 'nodeId': nodeId, 'online': isOnline, - 'ownerId': ownerId, - 'productId': productId, 'productName': productName, - 'sub': isSub, 'timeZone': timeZone, 'updateTime': updateTime, 'uuid': uuid, diff --git a/lib/features/devices/model/function_model.dart b/lib/features/devices/model/function_model.dart index 82391ec..24a5d93 100644 --- a/lib/features/devices/model/function_model.dart +++ b/lib/features/devices/model/function_model.dart @@ -3,7 +3,7 @@ import 'package:syncrow_app/utils/resource_manager/constants.dart'; class FunctionModel { String? code; FunctionType? type; - ValueModel? values; + dynamic values; FunctionModel({ required this.code, diff --git a/lib/features/devices/model/room_model.dart b/lib/features/devices/model/room_model.dart index 79c043e..7a00b43 100644 --- a/lib/features/devices/model/room_model.dart +++ b/lib/features/devices/model/room_model.dart @@ -1,14 +1,16 @@ import 'package:syncrow_app/features/devices/model/device_model.dart'; +import 'package:syncrow_app/utils/resource_manager/constants.dart'; class RoomModel { - final int? id; + final String? id; final String? name; - + final SpaceType type; List? devices; RoomModel({ required this.id, required this.name, + required this.type, required this.devices, }); @@ -16,6 +18,7 @@ class RoomModel { return { 'id': id, 'name': name, + 'type': type, 'devices': devices, }; } @@ -28,9 +31,10 @@ class RoomModel { } } return RoomModel( - id: json['roomId'], - name: json['roomName'], - devices: devices, + id: json['uuid'], + name: json['name'], + type: spaceTypesMap[json['type']]!, + devices: [], ); } } diff --git a/lib/features/devices/view/widgets/ACs/ac_interface_temp_unit.dart b/lib/features/devices/view/widgets/ACs/ac_interface_temp_unit.dart index f417936..883e103 100644 --- a/lib/features/devices/view/widgets/ACs/ac_interface_temp_unit.dart +++ b/lib/features/devices/view/widgets/ACs/ac_interface_temp_unit.dart @@ -91,10 +91,10 @@ class AcInterfaceTempUnit extends StatelessWidget { value = double.parse(valueAsString); DevicesCubit.getInstance().deviceControl( DeviceControlModel( - deviceId: acDevice.id, + deviceId: acDevice.uuid, code: 'temp_set', value: value * 10), - acDevice.id!); + acDevice.uuid!); } }, ), @@ -121,10 +121,10 @@ class AcInterfaceTempUnit extends StatelessWidget { if (setToTemp > 20) { DevicesCubit.getInstance().deviceControl( DeviceControlModel( - deviceId: acDevice.id, + deviceId: acDevice.uuid, code: 'temp_set', value: (setToTemp - 0.5) * 10), - acDevice.id!); + acDevice.uuid!); } }, child: SvgPicture.asset( @@ -171,10 +171,10 @@ class AcInterfaceTempUnit extends StatelessWidget { if (setToTemp < 30) { DevicesCubit.getInstance().deviceControl( DeviceControlModel( - deviceId: acDevice.id, + deviceId: acDevice.uuid, code: 'temp_set', value: (setToTemp + 0.5) * 10), - acDevice.id!); + acDevice.uuid!); } }, child: SvgPicture.asset( diff --git a/lib/features/devices/view/widgets/ACs/ac_mode_control_unit.dart b/lib/features/devices/view/widgets/ACs/ac_mode_control_unit.dart index 1260eec..e28a402 100644 --- a/lib/features/devices/view/widgets/ACs/ac_mode_control_unit.dart +++ b/lib/features/devices/view/widgets/ACs/ac_mode_control_unit.dart @@ -42,10 +42,10 @@ class _ACModeControlUnitState extends State { DevicesCubit.getInstance().deviceControl( DeviceControlModel( - deviceId: widget.acDevice.id, + deviceId: widget.acDevice.uuid, code: 'level', value: reversedFanSpeedsMap[fanSpeed]!), - widget.acDevice.id!); + widget.acDevice.uuid!); }, child: DefaultContainer( height: 55, @@ -68,10 +68,10 @@ class _ACModeControlUnitState extends State { tempMode = tempModesMap[getNextItem(tempModesMap, tempMode)]!; DevicesCubit.getInstance().deviceControl( DeviceControlModel( - deviceId: widget.acDevice.id, + deviceId: widget.acDevice.uuid, code: 'mode', value: reversedTempModesMap[tempMode]!), - widget.acDevice.id!); + widget.acDevice.uuid!); }, child: DefaultContainer( height: 55, diff --git a/lib/features/devices/view/widgets/presence_sensors/parameter_control_dialog.dart b/lib/features/devices/view/widgets/presence_sensors/parameter_control_dialog.dart index 1d22095..53e3fea 100644 --- a/lib/features/devices/view/widgets/presence_sensors/parameter_control_dialog.dart +++ b/lib/features/devices/view/widgets/presence_sensors/parameter_control_dialog.dart @@ -150,10 +150,10 @@ class ParameterControlDialogState extends State { DevicesCubit.getInstance().deviceControl( DeviceControlModel( - deviceId: widget.sensor.id, + deviceId: widget.sensor.uuid, code: widget.controlCode, value: widget.value), - widget.sensor.id ?? ''); + widget.sensor.uuid ?? ''); }, child: Center( child: BodyMedium( diff --git a/lib/features/devices/view/widgets/presence_sensors/parameters_list.dart b/lib/features/devices/view/widgets/presence_sensors/parameters_list.dart index f155064..cad1776 100644 --- a/lib/features/devices/view/widgets/presence_sensors/parameters_list.dart +++ b/lib/features/devices/view/widgets/presence_sensors/parameters_list.dart @@ -313,11 +313,11 @@ Widget listItem( if (wallSensor.isOnline ?? false) { DevicesCubit.getInstance().deviceControl( DeviceControlModel( - deviceId: wallSensor.id, + deviceId: wallSensor.uuid, code: 'indicator', value: value, ), - wallSensor.id ?? ''); + wallSensor.uuid ?? ''); } else { ScaffoldMessenger.of(context).showSnackBar( const SnackBar( diff --git a/lib/features/devices/view/widgets/three_gang/three_gang_interface_body.dart b/lib/features/devices/view/widgets/three_gang/three_gang_interface_body.dart index aef7ba0..7b2cfdf 100644 --- a/lib/features/devices/view/widgets/three_gang/three_gang_interface_body.dart +++ b/lib/features/devices/view/widgets/three_gang/three_gang_interface_body.dart @@ -34,7 +34,7 @@ class ThreeGangInterfaceBody extends StatelessWidget { GangSwitch( threeGangSwitch: device, control: DeviceControlModel( - deviceId: device.id, + deviceId: device.uuid, // code: 'switch_1', code: device.status[0].code, // value: true, @@ -60,7 +60,7 @@ class ThreeGangInterfaceBody extends StatelessWidget { // deviceId: 'bfe10693d4fd263206ocq9', // code: 'switch_2', // value: true, - deviceId: device.id, + deviceId: device.uuid, code: device.status[1].code, value: device.status[1].value, ), @@ -84,7 +84,7 @@ class ThreeGangInterfaceBody extends StatelessWidget { // deviceId: 'bfe10693d4fd263206ocq9', // code: 'switch_3', // value: true, - deviceId: device.id, + deviceId: device.uuid, code: device.status[2].code, value: device.status[2].value, ), @@ -120,27 +120,27 @@ class ThreeGangInterfaceBody extends StatelessWidget { onTap: () { DevicesCubit.getInstance().deviceControl( DeviceControlModel( - deviceId: device.id, + deviceId: device.uuid, code: 'switch_1', value: true, ), - device.id!, + device.uuid!, ); DevicesCubit.getInstance().deviceControl( DeviceControlModel( - deviceId: device.id, + deviceId: device.uuid, code: 'switch_2', value: true, ), - device.id!, + device.uuid!, ); DevicesCubit.getInstance().deviceControl( DeviceControlModel( - deviceId: device.id, + deviceId: device.uuid, code: 'switch_3', value: true, ), - device.id!, + device.uuid!, ); }, child: Stack( @@ -252,27 +252,27 @@ class ThreeGangInterfaceBody extends StatelessWidget { onTap: () { DevicesCubit.getInstance().deviceControl( DeviceControlModel( - deviceId: device.id, + deviceId: device.uuid, code: 'switch_1', value: false, ), - device.id!, + device.uuid!, ); DevicesCubit.getInstance().deviceControl( DeviceControlModel( - deviceId: device.id, + deviceId: device.uuid, code: 'switch_2', value: false, ), - device.id!, + device.uuid!, ); DevicesCubit.getInstance().deviceControl( DeviceControlModel( - deviceId: device.id, + deviceId: device.uuid, code: 'switch_3', value: false, ), - device.id!, + device.uuid!, ); }, child: Stack( diff --git a/lib/features/shared_widgets/custom_switch.dart b/lib/features/shared_widgets/custom_switch.dart index e83a69e..85262d0 100644 --- a/lib/features/shared_widgets/custom_switch.dart +++ b/lib/features/shared_widgets/custom_switch.dart @@ -26,7 +26,7 @@ class CustomSwitch extends StatelessWidget { onTap: () { DevicesCubit.getInstance().deviceControl( DeviceControlModel( - deviceId: device.id, + deviceId: device.uuid, code: device.status .firstWhere((status) => status.code == "switch") .code, @@ -34,7 +34,7 @@ class CustomSwitch extends StatelessWidget { .firstWhere((status) => status.code == "switch") .value!, ), - device.id!, + device.uuid!, ); }, child: Container( diff --git a/lib/services/api/api_links_endpoints.dart b/lib/services/api/api_links_endpoints.dart index 6e5efc0..a920839 100644 --- a/lib/services/api/api_links_endpoints.dart +++ b/lib/services/api/api_links_endpoints.dart @@ -1,7 +1,9 @@ abstract class ApiEndpoints { static const String baseUrl = 'https://syncrow.azurewebsites.net'; + // static const String baseUrl = 'http://100.107.182.63:4001'; //Localhost + +////////////////////////////////////// Authentication /////////////////////////////// - // Authentication static const String signUp = '$baseUrl/authentication/user/signup'; static const String login = '$baseUrl/authentication/user/login'; static const String deleteUser = '$baseUrl/authentication/user/delete/{id}'; @@ -10,16 +12,100 @@ abstract class ApiEndpoints { static const String forgetPassword = '$baseUrl/authentication/user/forget-password'; -// Spaces - static const String spaces = '$baseUrl/home'; - static const String rooms = '$baseUrl/room'; +////////////////////////////////////// Spaces /////////////////////////////////////// - // Devices - static const String control = '$baseUrl/device/control'; - static const String devicesByRoom = '$baseUrl/device/room'; - // static const String deviceStatus = '$baseUrl/device/status/'; - static const String deviceStatus = '$baseUrl/device/'; + ///Community Module +//POST + static const String addCommunity = '$baseUrl/community'; + static const String addCommunityToUser = '$baseUrl/community/user'; +//GET + static const String communityByUuid = '$baseUrl/community/{communityUuid}'; + static const String communityChild = + '$baseUrl/community/child/{communityUuid}'; + static const String communityUser = '$baseUrl/community/user/{userUuid}'; +//PUT + static const String renameCommunity = + '$baseUrl/community/rename/{communityUuid}'; - //groups - static const String groups = '$baseUrl/group'; + ///Building Module +//POST + static const String addBuilding = '$baseUrl/building'; + static const String addBuildingToUser = '$baseUrl/building/user'; +//GET + static const String buildingByUuid = '$baseUrl/building/{buildingUuid}'; + static const String buildingChild = '$baseUrl/building/child/{buildingUuid}'; + static const String buildingParent = + '$baseUrl/building/parent/{buildingUuid}'; + static const String buildingUser = '$baseUrl/building/user/{userUuid}'; +//PUT + static const String renameBuilding = + '$baseUrl/building/rename/{buildingUuid}'; + + ///Floor Module +//POST + static const String addFloor = '$baseUrl/floor'; + static const String addFloorToUser = '$baseUrl/floor/user'; +//GET + static const String floorByUuid = '$baseUrl/floor/{floorUuid}'; + static const String floorChild = '$baseUrl/floor/child/{floorUuid}'; + static const String floorParent = '$baseUrl/floor/parent/{floorUuid}'; + static const String floorUser = '$baseUrl/floor/user/{userUuid}'; +//PUT + static const String renameFloor = '$baseUrl/floor/rename/{floorUuid}'; + + ///Unit Module +//POST + static const String addUnit = '$baseUrl/unit'; + static const String addUnitToUser = '$baseUrl/unit/user'; +//GET + static const String unitByUuid = '$baseUrl/unit/'; + static const String unitChild = '$baseUrl/unit/child/'; + static const String unitParent = '$baseUrl/unit/parent/{unitUuid}'; + static const String unitUser = '$baseUrl/unit/user/'; +//PUT + static const String renameUnit = '$baseUrl/unit/rename/{unitUuid}'; + + ///Room Module +//POST + static const String addRoom = '$baseUrl/room'; + static const String addRoomToUser = '$baseUrl/room/user'; +//GET + static const String roomByUuid = '$baseUrl/room/{roomUuid}'; + static const String roomParent = '$baseUrl/room/parent/{roomUuid}'; + static const String roomUser = '$baseUrl/room/user/{userUuid}'; +//PUT + static const String renameRoom = '$baseUrl/room/rename/{roomUuid}'; + + ///Group Module +//POST + static const String addGroup = '$baseUrl/group'; + static const String controlGroup = '$baseUrl/group/control'; +//GET + static const String groupBySpace = '$baseUrl/group/space/{spaceUuid}'; + static const String groupByUuid = '$baseUrl/group/{groupUuid}'; +//DELETE + static const String deleteGroup = '$baseUrl/group/{groupUuid}'; + +////////////////////////////////////// Devices /////////////////////////////////////// + ///Device Module +//POST + static const String addDeviceToRoom = '$baseUrl/device/room'; + static const String addDeviceToGroup = '$baseUrl/device/group'; + static const String controlDevice = '$baseUrl/device/control'; +//GET + static const String deviceByRoom = '$baseUrl/device/room'; + static const String deviceByUuid = '$baseUrl/device/{deviceUuid}'; + static const String deviceFunctions = + '$baseUrl/device/{deviceUuid}/functions'; + static const String deviceFunctionsStatus = + '$baseUrl/device/{deviceUuid}/functions/status'; + + ///Device Permission Module +//POST + static const String addDevicePermission = '$baseUrl/device-permission/add'; +//GET + static const String devicePermissionList = '$baseUrl/device-permission/list'; +//PUT + static const String editDevicePermission = + '$baseUrl/device-permission/edit/{userId}'; } diff --git a/lib/services/api/devices_api.dart b/lib/services/api/devices_api.dart index 97c5588..7d0e4fc 100644 --- a/lib/services/api/devices_api.dart +++ b/lib/services/api/devices_api.dart @@ -1,3 +1,5 @@ +import 'dart:async'; + import 'package:syncrow_app/features/devices/model/device_category_model.dart'; import 'package:syncrow_app/features/devices/model/device_control_model.dart'; import 'package:syncrow_app/features/devices/model/device_model.dart'; @@ -11,7 +13,7 @@ class DevicesAPI { DeviceControlModel controlModel) async { try { final response = await _httpService.post( - path: ApiEndpoints.control, + path: ApiEndpoints.controlDevice, body: controlModel.toJson(), showServerMessage: false, expectedResponseModel: (json) { @@ -24,7 +26,7 @@ class DevicesAPI { } } - static Future> fetchGroups(int spaceId) async { + static Future> fetchGroups(String spaceId) async { Map params = { "homeId": spaceId, "pageSize": 100, @@ -32,7 +34,7 @@ class DevicesAPI { }; final response = await _httpService.get( - path: ApiEndpoints.groups, + path: ApiEndpoints.groupBySpace.replaceAll("{spaceUuid}", spaceId), queryParameters: params, showServerMessage: false, expectedResponseModel: (json) => @@ -43,7 +45,8 @@ class DevicesAPI { static Future> getDeviceStatus(String deviceId) async { final response = await _httpService.get( - path: '${ApiEndpoints.deviceStatus}/$deviceId/functions/status', + path: ApiEndpoints.deviceFunctionsStatus + .replaceAll('{deviceUuid}', deviceId), showServerMessage: false, expectedResponseModel: (json) { return json; @@ -52,14 +55,20 @@ class DevicesAPI { return response; } - static Future> getDevicesByRoomId(int roomId) async { + static Future> getDevicesByRoomId(String roomId) async { + // print("Room ID: $roomId"); final response = await _httpService.get( - path: ApiEndpoints.devicesByRoom, - queryParameters: {"roomId": roomId, "pageSize": 10}, + path: ApiEndpoints.deviceByRoom, + queryParameters: {"roomUuid": roomId}, showServerMessage: false, expectedResponseModel: (json) { + if (json == null || json.isEmpty || json == []) { + print('json: $json'); + return []; + } + print('json: $json'); List devices = []; - for (var device in json['devices']) { + for (var device in json) { devices.add(DeviceModel.fromJson(device)); } return devices; diff --git a/lib/services/api/spaces_api.dart b/lib/services/api/spaces_api.dart index 664c3a7..7d6f476 100644 --- a/lib/services/api/spaces_api.dart +++ b/lib/services/api/spaces_api.dart @@ -8,29 +8,25 @@ import 'package:syncrow_app/services/api/http_service.dart'; class SpacesAPI { static final HTTPService _httpService = HTTPService(); - static Future> getSpaces() async { + static Future> getUnitsByUserId() async { var uuid = await const FlutterSecureStorage().read(key: UserModel.userUuidKey); final response = await _httpService.get( - path: ApiEndpoints.spaces, - queryParameters: { - "userUuid": uuid, - }, + path: "${ApiEndpoints.unitUser}$uuid", showServerMessage: false, expectedResponseModel: (json) => SpaceModel.fromJsonList(json), ); return response; } - //get rooms by space id - static Future> getRoomsBySpaceId(int spaceId) async { + static Future> getRoomsBySpaceId(String unitId) async { final response = await _httpService.get( - path: ApiEndpoints.rooms, - queryParameters: {"homeId": spaceId}, + path: "${ApiEndpoints.unitChild}$unitId", + queryParameters: {"page": 1, "pageSize": 10}, showServerMessage: false, expectedResponseModel: (json) { List rooms = []; - for (var room in json) { + for (var room in json['children']) { rooms.add(RoomModel.fromJson(room)); } return rooms; diff --git a/lib/utils/resource_manager/constants.dart b/lib/utils/resource_manager/constants.dart index e1748dd..be51f63 100644 --- a/lib/utils/resource_manager/constants.dart +++ b/lib/utils/resource_manager/constants.dart @@ -19,6 +19,16 @@ abstract class Constants { static const String token = ''; } +enum SpaceType { Unit, Building, Floor, Room, Community } + +Map spaceTypesMap = { + "unit": SpaceType.Unit, + "building": SpaceType.Building, + "floor": SpaceType.Floor, + "room": SpaceType.Room, + "community": SpaceType.Community, +}; + enum DeviceType { AC, LightBulb, @@ -32,26 +42,10 @@ enum DeviceType { Other, } -// Map devicesTypesMap = { -// "AC": DeviceType.AC, -// "LB": DeviceType.LightBulb, -// "DL": DeviceType.DoorLock, -// "WC": DeviceType.Curtain, -// "WB": DeviceType.Blind, -// "3G": DeviceType.ThreeGang, -// "GW": DeviceType.Gateway, -// "CPS": DeviceType.CeilingSensor, -// "WPS": DeviceType.WallSensor, -// "Other": DeviceType.Other, -// }; -//AC wzdcrqh0 -// GW wp8ticoo2bhumwgb -// CPS d3ci7gcn -// DL awu7anehyu5q1iu8 -// WPS awarhusb -// 3G 1a6vgvyi enum FunctionType { Boolean, Enum, Integer, Raw, String } +enum ValueACRange { LOW, MIDDLE, HIGH, AUTO } + Map functionTypesMap = { "Boolean": FunctionType.Boolean, "Enum": FunctionType.Enum, @@ -60,12 +54,12 @@ Map functionTypesMap = { "String": FunctionType.String, }; Map devicesTypesMap = { - "wzdcrqh0": DeviceType.AC, - "wp8ticoo2bhumwgb": DeviceType.Gateway, - "d3ci7gcn": DeviceType.CeilingSensor, - "awu7anehyu5q1iu8": DeviceType.DoorLock, - "awarhusb": DeviceType.WallSensor, - "1a6vgvyi": DeviceType.ThreeGang, + "AC": DeviceType.AC, + "GW": DeviceType.Gateway, + "CPS": DeviceType.CeilingSensor, + "DL": DeviceType.DoorLock, + "WPS": DeviceType.WallSensor, + "3G": DeviceType.ThreeGang, }; Map> devicesFunctionsMap = { DeviceType.AC: [ @@ -77,18 +71,22 @@ Map> devicesFunctionsMap = { code: 'mode', type: functionTypesMap['Enum'], values: ValueModel.fromJson({ - "range": ["cold", "hot", "wind"] + // "range": ["cold", "hot", "wind"] })), FunctionModel( - code: 'temp_set', - type: functionTypesMap['Integer'], - values: ValueModel.fromJson( - {"unit": "℃", "min": 200, "max": 300, "scale": 1, "step": 5})), + code: 'temp_set', + type: functionTypesMap['Integer'], + values: ValueModel.fromJson( + { + // "unit": {"min": 200, "max": 300, "scale": 1, "step": 5}, + }, + ), + ), FunctionModel( code: 'level', type: functionTypesMap['Enum'], values: ValueModel.fromJson({ - "range": ["low", "middle", "high", "auto"] + // "range": ["low", "middle", "high", "auto"] })), FunctionModel( code: 'child_lock',