mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-08-26 04:19:40 +00:00
models
This commit is contained in:
27
lib/features/app_layout/model/community_model.dart
Normal file
27
lib/features/app_layout/model/community_model.dart
Normal file
@ -0,0 +1,27 @@
|
||||
class Community {
|
||||
final String uuid;
|
||||
final String name;
|
||||
final String description;
|
||||
|
||||
Community({
|
||||
required this.uuid,
|
||||
required this.name,
|
||||
required this.description,
|
||||
});
|
||||
|
||||
factory Community.fromJson(Map<String, dynamic> json) {
|
||||
return Community(
|
||||
uuid: json['uuid'],
|
||||
name: json['name'],
|
||||
description: json['description'],
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'uuid': uuid,
|
||||
'name': name,
|
||||
'description': description,
|
||||
};
|
||||
}
|
||||
}
|
@ -1,36 +1,45 @@
|
||||
import 'package:syncrow_app/features/app_layout/model/community_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/room_model.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
|
||||
class SpaceModel {
|
||||
final String? id;
|
||||
final String? name;
|
||||
final SpaceType type;
|
||||
late List<RoomModel>? rooms;
|
||||
final String id;
|
||||
final String name;
|
||||
final Community community;
|
||||
final List<SubSpaceModel> subspaces;
|
||||
|
||||
SpaceModel({
|
||||
required this.type,
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.rooms,
|
||||
required this.community,
|
||||
this.subspaces = const [], // Default to an empty list
|
||||
});
|
||||
|
||||
/// Converts the instance into JSON format.
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'name': name,
|
||||
'rooms': rooms,
|
||||
'spaceName': name,
|
||||
'community': community.toJson(),
|
||||
'subspaces': subspaces.map((room) => room.toJson()).toList(),
|
||||
};
|
||||
}
|
||||
|
||||
/// Factory constructor to create an instance from JSON.
|
||||
factory SpaceModel.fromJson(Map<String, dynamic> json) {
|
||||
final spaceData = json['space'] as Map<String, dynamic>? ?? {};
|
||||
|
||||
return SpaceModel(
|
||||
id: json['uuid'],
|
||||
name: json['name'],
|
||||
type: spaceTypesMap[json['type']]!,
|
||||
rooms: [],
|
||||
id: json['uuid'] ?? '',
|
||||
name: spaceData['spaceName'] ?? 'Unnamed Space',
|
||||
community: Community.fromJson(spaceData['community'] ?? {}),
|
||||
subspaces: (spaceData['subspaces'] as List<dynamic>?)
|
||||
?.map((item) => SubSpaceModel.fromJson(item))
|
||||
.toList() ??
|
||||
[],
|
||||
);
|
||||
}
|
||||
|
||||
/// Helper method to parse a list of SpaceModel from JSON.
|
||||
static List<SpaceModel> fromJsonList(List<dynamic> jsonList) {
|
||||
return jsonList.map((item) => SpaceModel.fromJson(item)).toList();
|
||||
}
|
||||
|
@ -1,16 +1,13 @@
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
|
||||
class RoomModel {
|
||||
class SubSpaceModel {
|
||||
final String? id;
|
||||
final String? name;
|
||||
final SpaceType type;
|
||||
List<DeviceModel>? devices;
|
||||
|
||||
RoomModel({
|
||||
SubSpaceModel({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.type,
|
||||
required this.devices,
|
||||
});
|
||||
|
||||
@ -18,22 +15,20 @@ class RoomModel {
|
||||
return {
|
||||
'id': id,
|
||||
'name': name,
|
||||
'type': type,
|
||||
'devices': devices,
|
||||
};
|
||||
}
|
||||
|
||||
factory RoomModel.fromJson(Map<String, dynamic> json) {
|
||||
factory SubSpaceModel.fromJson(Map<String, dynamic> json) {
|
||||
List<DeviceModel> devices = [];
|
||||
if (json['devices'] != null) {
|
||||
for (var device in json['devices']) {
|
||||
devices.add(DeviceModel.fromJson(device));
|
||||
}
|
||||
}
|
||||
return RoomModel(
|
||||
return SubSpaceModel(
|
||||
id: json['uuid'],
|
||||
name: json['name'],
|
||||
type: spaceTypesMap[json['type']]!,
|
||||
devices: [],
|
||||
);
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ abstract class ApiEndpoints {
|
||||
static const String addUnitToUser = '/unit/user';
|
||||
//GET
|
||||
static const String unitByUuid = '/unit/';
|
||||
static const String unitChild = '/unit/child/';
|
||||
static const String listSubspace = '/communities/{communityUuid}/spaces/{spaceUuid}/subspaces';
|
||||
static const String unitParent = '/unit/parent/{unitUuid}';
|
||||
static const String unitUser = '/unit/user/';
|
||||
static const String invitationCode = '/unit/{unitUuid}/invitation-code';
|
||||
@ -75,6 +75,11 @@ abstract class ApiEndpoints {
|
||||
//PUT
|
||||
static const String renameRoom = '/room/{roomUuid}';
|
||||
|
||||
|
||||
//SPACE Module
|
||||
//GET
|
||||
static const String userSpaces = '/user/{userUuid}/spaces';
|
||||
|
||||
///Group Module
|
||||
//POST
|
||||
static const String addGroup = '/group';
|
||||
|
Reference in New Issue
Block a user