mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-08-26 04:19:40 +00:00
create subspace
This commit is contained in:
@ -61,7 +61,9 @@ class CreateUnitBloc extends Bloc<CreateUnitEvent, CreateUnitState> {
|
||||
var storage = const FlutterSecureStorage();
|
||||
var userId = await storage.read(key: UserModel.userUuidKey) ?? '';
|
||||
|
||||
Map<String, String> communityBody = {'communityName': event.communityName};
|
||||
Map<String, String> communityBody = {
|
||||
'communityName': event.communityName
|
||||
};
|
||||
final response = await HomeCreation.createCommunity(communityBody);
|
||||
if (response['data']['uuid'] != '') {
|
||||
// final result =
|
||||
@ -75,15 +77,22 @@ class CreateUnitBloc extends Bloc<CreateUnitEvent, CreateUnitState> {
|
||||
|
||||
if (buildingId.isNotEmpty) {
|
||||
final floorId = await _createFloor(
|
||||
floorName: event.floorName, buildingId: buildingId, userId: userId);
|
||||
floorName: event.floorName,
|
||||
buildingId: buildingId,
|
||||
userId: userId);
|
||||
|
||||
if (floorId.isNotEmpty) {
|
||||
final unitId =
|
||||
await _createUnit(unitName: event.unitName, floorId: floorId, userId: userId);
|
||||
final unitId = await _createUnit(
|
||||
unitName: event.unitName, floorId: floorId, userId: userId);
|
||||
|
||||
if (unitId.isNotEmpty && rooms.isNotEmpty) {
|
||||
rooms.forEach((room) async {
|
||||
await _createNewRoom(roomName: room, unitId: unitId, userId: userId);
|
||||
await _createNewRoom(
|
||||
roomName: room,
|
||||
unitId: unitId,
|
||||
userId: userId,
|
||||
communityId: response['data']['uuid'],
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -99,7 +108,8 @@ class CreateUnitBloc extends Bloc<CreateUnitEvent, CreateUnitState> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> _assignToCommunity({required String communityId, required String userId}) async {
|
||||
Future<bool> _assignToCommunity(
|
||||
{required String communityId, required String userId}) async {
|
||||
try {
|
||||
Map<String, String> body = {
|
||||
'communityUuid': communityId,
|
||||
@ -114,9 +124,14 @@ Future<bool> _assignToCommunity({required String communityId, required String us
|
||||
}
|
||||
|
||||
Future<String> _createBuilding(
|
||||
{required String buildingName, required String communityId, required String userId}) async {
|
||||
{required String buildingName,
|
||||
required String communityId,
|
||||
required String userId}) async {
|
||||
try {
|
||||
Map<String, String> body = {'buildingName': buildingName, 'communityUuid': communityId};
|
||||
Map<String, String> body = {
|
||||
'buildingName': buildingName,
|
||||
'communityUuid': communityId
|
||||
};
|
||||
final response = await HomeCreation.createBuilding(body);
|
||||
// if (response['data']['uuid'] != '') {
|
||||
// final result = await _assignToBuilding(buildingId: response['data']['uuid'], userId: userId);
|
||||
@ -130,7 +145,8 @@ Future<String> _createBuilding(
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> _assignToBuilding({required String buildingId, required String userId}) async {
|
||||
Future<bool> _assignToBuilding(
|
||||
{required String buildingId, required String userId}) async {
|
||||
try {
|
||||
Map<String, String> body = {
|
||||
'buildingUuid': buildingId,
|
||||
@ -145,9 +161,14 @@ Future<bool> _assignToBuilding({required String buildingId, required String user
|
||||
}
|
||||
|
||||
Future<String> _createFloor(
|
||||
{required String floorName, required String buildingId, required String userId}) async {
|
||||
{required String floorName,
|
||||
required String buildingId,
|
||||
required String userId}) async {
|
||||
try {
|
||||
Map<String, String> body = {'floorName': floorName, 'buildingUuid': buildingId};
|
||||
Map<String, String> body = {
|
||||
'floorName': floorName,
|
||||
'buildingUuid': buildingId
|
||||
};
|
||||
final response = await HomeCreation.createFloor(body);
|
||||
// if (response['data']['uuid'] != '') {
|
||||
// final result = await _assignToFloor(buildingId: response['data']['uuid'], userId: userId);
|
||||
@ -161,7 +182,8 @@ Future<String> _createFloor(
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> _assignToFloor({required String buildingId, required String userId}) async {
|
||||
Future<bool> _assignToFloor(
|
||||
{required String buildingId, required String userId}) async {
|
||||
try {
|
||||
Map<String, String> body = {
|
||||
'floorUuid': buildingId,
|
||||
@ -176,12 +198,15 @@ Future<bool> _assignToFloor({required String buildingId, required String userId}
|
||||
}
|
||||
|
||||
Future<String> _createUnit(
|
||||
{required String unitName, required String floorId, required String userId}) async {
|
||||
{required String unitName,
|
||||
required String floorId,
|
||||
required String userId}) async {
|
||||
try {
|
||||
Map<String, String> body = {'unitName': unitName, 'floorUuid': floorId};
|
||||
final response = await HomeCreation.createUnit(body);
|
||||
if (response['data']['uuid'] != '') {
|
||||
final result = await _assignToUnit(unitId: response['data']['uuid'], userId: userId);
|
||||
final result =
|
||||
await _assignToUnit(unitId: response['data']['uuid'], userId: userId);
|
||||
|
||||
return result ? response['data']['uuid'] : '';
|
||||
} else {
|
||||
@ -192,7 +217,8 @@ Future<String> _createUnit(
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> _assignToUnit({required String unitId, required String userId}) async {
|
||||
Future<bool> _assignToUnit(
|
||||
{required String unitId, required String userId}) async {
|
||||
try {
|
||||
Map<String, String> body = {
|
||||
'unitUuid': unitId,
|
||||
@ -207,10 +233,14 @@ Future<bool> _assignToUnit({required String unitId, required String userId}) asy
|
||||
}
|
||||
|
||||
Future<String> _createNewRoom(
|
||||
{required String roomName, required String unitId, required String userId}) async {
|
||||
{required String roomName,
|
||||
required String unitId,
|
||||
required String userId,
|
||||
required String communityId}) async {
|
||||
try {
|
||||
Map<String, String> body = {'roomName': roomName, 'unitUuid': unitId};
|
||||
final response = await HomeCreation.createRoom(body);
|
||||
Map<String, String> body = {'subspaceName': roomName};
|
||||
final response = await HomeCreation.createRoom(
|
||||
communityId: communityId, spaceId: unitId, body: body);
|
||||
// if (response['data']['uuid'] != '') {
|
||||
// final result = await _assignToRoom(roomId: response['data']['uuid'], userId: userId);
|
||||
|
||||
@ -223,7 +253,8 @@ Future<String> _createNewRoom(
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> _assignToRoom({required String roomId, required String userId}) async {
|
||||
Future<bool> _assignToRoom(
|
||||
{required String roomId, required String userId}) async {
|
||||
try {
|
||||
Map<String, String> body = {
|
||||
'roomUuid': roomId,
|
||||
|
@ -107,10 +107,13 @@ class ManageUnitBloc extends Bloc<ManageUnitEvent, ManageUnitState> {
|
||||
}
|
||||
|
||||
_addNewRoom(AddNewRoom event, Emitter<ManageUnitState> emit) async {
|
||||
Map<String, String> body = {'roomName': event.roomName};
|
||||
Map<String, String> body = {'subspaceName': event.roomName};
|
||||
try {
|
||||
emit(LoadingState());
|
||||
final response = await HomeCreation.createRoom(body);
|
||||
final response = await HomeCreation.createRoom(
|
||||
communityId: event.unit.community.uuid,
|
||||
spaceId: event.unit.id,
|
||||
body: body);
|
||||
if (response['data']['uuid'] != '') {
|
||||
final roomsList = await SpacesAPI.getSubSpaceBySpaceId(
|
||||
event.unit.community.uuid, event.unit.id);
|
||||
|
@ -109,7 +109,7 @@ class RoomsView extends StatelessWidget {
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
BodyMedium(
|
||||
text: 'Add Space',
|
||||
text: 'Add Room',
|
||||
fontColor: ColorsManager.primaryColor,
|
||||
),
|
||||
],
|
||||
|
@ -65,6 +65,11 @@ abstract class ApiEndpoints {
|
||||
//PUT
|
||||
static const String renameUnit = '/unit/{unitUuid}';
|
||||
|
||||
//Subspace Module
|
||||
//POST
|
||||
static const String addSubSpace =
|
||||
'/communities/{communityUuid}/spaces/{spaceUuid}/subspaces';
|
||||
|
||||
///Room Module
|
||||
//POST
|
||||
static const String addRoom = '/room';
|
||||
@ -113,8 +118,10 @@ abstract class ApiEndpoints {
|
||||
static const String deviceByUuid = '/device/{deviceUuid}';
|
||||
static const String deviceFunctions = '/device/{deviceUuid}/functions';
|
||||
static const String gatewayApi = '/device/gateway/{gatewayUuid}/devices';
|
||||
static const String deviceFunctionsStatus = '/device/{deviceUuid}/functions/status';
|
||||
static const String powerClamp = '/device/{powerClampUuid}/power-clamp/status';
|
||||
static const String deviceFunctionsStatus =
|
||||
'/device/{deviceUuid}/functions/status';
|
||||
static const String powerClamp =
|
||||
'/device/{powerClampUuid}/power-clamp/status';
|
||||
|
||||
///Device Permission Module
|
||||
//POST
|
||||
|
@ -1,5 +1,6 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
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';
|
||||
@ -174,8 +175,6 @@ class DevicesAPI {
|
||||
return response;
|
||||
} catch (e) {
|
||||
// Log the error if needed
|
||||
print("Error fetching devices for room: $e");
|
||||
|
||||
// Return an empty list in case of error
|
||||
return <DeviceModel>[];
|
||||
}
|
||||
|
@ -4,7 +4,8 @@ import 'package:syncrow_app/services/api/http_service.dart';
|
||||
class HomeCreation {
|
||||
static final HTTPService _httpService = HTTPService();
|
||||
|
||||
static Future<Map<String, dynamic>> createCommunity(Map<String, String> body) async {
|
||||
static Future<Map<String, dynamic>> createCommunity(
|
||||
Map<String, String> body) async {
|
||||
try {
|
||||
final response = await _httpService.post(
|
||||
path: ApiEndpoints.addCommunity,
|
||||
@ -20,7 +21,8 @@ class HomeCreation {
|
||||
}
|
||||
}
|
||||
|
||||
static Future<Map<String, dynamic>> assignUserToCommunity(Map<String, String> body) async {
|
||||
static Future<Map<String, dynamic>> assignUserToCommunity(
|
||||
Map<String, String> body) async {
|
||||
try {
|
||||
final response = await _httpService.post(
|
||||
path: ApiEndpoints.addCommunityToUser,
|
||||
@ -36,7 +38,8 @@ class HomeCreation {
|
||||
}
|
||||
}
|
||||
|
||||
static Future<Map<String, dynamic>> createBuilding(Map<String, String> body) async {
|
||||
static Future<Map<String, dynamic>> createBuilding(
|
||||
Map<String, String> body) async {
|
||||
try {
|
||||
final response = await _httpService.post(
|
||||
path: ApiEndpoints.addBuilding,
|
||||
@ -52,7 +55,8 @@ class HomeCreation {
|
||||
}
|
||||
}
|
||||
|
||||
static Future<Map<String, dynamic>> assignUserToBuilding(Map<String, String> body) async {
|
||||
static Future<Map<String, dynamic>> assignUserToBuilding(
|
||||
Map<String, String> body) async {
|
||||
try {
|
||||
final response = await _httpService.post(
|
||||
path: ApiEndpoints.addBuildingToUser,
|
||||
@ -68,7 +72,8 @@ class HomeCreation {
|
||||
}
|
||||
}
|
||||
|
||||
static Future<Map<String, dynamic>> createFloor(Map<String, String> body) async {
|
||||
static Future<Map<String, dynamic>> createFloor(
|
||||
Map<String, String> body) async {
|
||||
try {
|
||||
final response = await _httpService.post(
|
||||
path: ApiEndpoints.addFloor,
|
||||
@ -84,7 +89,8 @@ class HomeCreation {
|
||||
}
|
||||
}
|
||||
|
||||
static Future<Map<String, dynamic>> assignUserToFloor(Map<String, String> body) async {
|
||||
static Future<Map<String, dynamic>> assignUserToFloor(
|
||||
Map<String, String> body) async {
|
||||
try {
|
||||
final response = await _httpService.post(
|
||||
path: ApiEndpoints.addBuildingToUser,
|
||||
@ -100,7 +106,8 @@ class HomeCreation {
|
||||
}
|
||||
}
|
||||
|
||||
static Future<Map<String, dynamic>> createUnit(Map<String, String> body) async {
|
||||
static Future<Map<String, dynamic>> createUnit(
|
||||
Map<String, String> body) async {
|
||||
try {
|
||||
final response = await _httpService.post(
|
||||
path: ApiEndpoints.addUnit,
|
||||
@ -116,7 +123,8 @@ class HomeCreation {
|
||||
}
|
||||
}
|
||||
|
||||
static Future<Map<String, dynamic>> assignUserToUnit(Map<String, String> body) async {
|
||||
static Future<Map<String, dynamic>> assignUserToUnit(
|
||||
Map<String, String> body) async {
|
||||
try {
|
||||
final response = await _httpService.post(
|
||||
path: ApiEndpoints.addUnitToUser,
|
||||
@ -132,10 +140,17 @@ class HomeCreation {
|
||||
}
|
||||
}
|
||||
|
||||
static Future<Map<String, dynamic>> createRoom(Map<String, String> body) async {
|
||||
static Future<Map<String, dynamic>> createRoom({
|
||||
required String communityId,
|
||||
required String spaceId,
|
||||
required Map<String, String> body,
|
||||
}) async {
|
||||
try {
|
||||
final fullPath = ApiEndpoints.addSubSpace
|
||||
.replaceAll('{communityUuid}', communityId)
|
||||
.replaceAll('{spaceUuid}', spaceId);
|
||||
final response = await _httpService.post(
|
||||
path: ApiEndpoints.addRoom,
|
||||
path: fullPath,
|
||||
body: body,
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
@ -148,8 +163,8 @@ class HomeCreation {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static Future<Map<String, dynamic>> assignUserToRoom(Map<String, String> body) async {
|
||||
static Future<Map<String, dynamic>> assignUserToRoom(
|
||||
Map<String, String> body) async {
|
||||
try {
|
||||
final response = await _httpService.post(
|
||||
path: ApiEndpoints.addRoomToUser,
|
||||
|
@ -39,10 +39,6 @@ class HomeManagementAPI {
|
||||
final path = ApiEndpoints.spaceDevices
|
||||
.replaceAll("{communityUuid}", communityUuid)
|
||||
.replaceAll("{spaceUuid}", spaceUuid);
|
||||
|
||||
// Debugging: Log the path
|
||||
print("Fetching devices with path: $path");
|
||||
|
||||
await _httpService.get(
|
||||
path: path,
|
||||
showServerMessage: false,
|
||||
@ -54,10 +50,8 @@ class HomeManagementAPI {
|
||||
);
|
||||
|
||||
// Debugging: Log successful fetch
|
||||
print("Successfully fetched ${list.length} devices.");
|
||||
} catch (e) {
|
||||
// Log the error for debugging
|
||||
print("Error fetching devices for the unit: $e");
|
||||
}
|
||||
|
||||
return list;
|
||||
|
Reference in New Issue
Block a user