create subspace

This commit is contained in:
hannathkadher
2024-10-31 11:30:35 +04:00
parent 36e5df38ee
commit dcccc4db3a
8 changed files with 123 additions and 74 deletions

View File

@ -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

View File

@ -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>[];
}

View File

@ -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,

View File

@ -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;