mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-11-27 09:04:56 +00:00
subspace model
This commit is contained in:
@ -1,25 +1,20 @@
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart';
|
||||
import 'package:syncrow_web/utils/constants/action_enum.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class SpaceTemplateModel {
|
||||
final String uuid;
|
||||
final DateTime createdAt;
|
||||
final DateTime updatedAt;
|
||||
final String? uuid;
|
||||
final String modelName;
|
||||
final bool disabled;
|
||||
final List<SubspaceTemplateModel> subspaceModels;
|
||||
final List<TagModel> tags;
|
||||
final List<SubspaceTemplateModel>? subspaceModels;
|
||||
final List<TagModel>? tags;
|
||||
String internalId;
|
||||
|
||||
SpaceTemplateModel({
|
||||
required this.uuid,
|
||||
this.uuid,
|
||||
String? internalId,
|
||||
required this.createdAt,
|
||||
required this.updatedAt,
|
||||
required this.modelName,
|
||||
required this.disabled,
|
||||
required this.subspaceModels,
|
||||
required this.tags,
|
||||
this.subspaceModels,
|
||||
this.tags,
|
||||
}) : internalId = internalId ?? const Uuid().v4();
|
||||
|
||||
factory SpaceTemplateModel.fromJson(Map<String, dynamic> json) {
|
||||
@ -28,28 +23,22 @@ class SpaceTemplateModel {
|
||||
return SpaceTemplateModel(
|
||||
uuid: json['uuid'] ?? '',
|
||||
internalId: internalId,
|
||||
createdAt: DateTime.parse(json['createdAt']),
|
||||
updatedAt: DateTime.parse(json['updatedAt']),
|
||||
modelName: json['modelName'] ?? '',
|
||||
disabled: json['disabled'] ?? false,
|
||||
subspaceModels: (json['subspaceModels'] as List)
|
||||
.map((item) => SubspaceTemplateModel.fromJson(item))
|
||||
.toList(),
|
||||
.map((item) => SubspaceTemplateModel.fromJson(item))
|
||||
.toList(),
|
||||
tags: (json['tags'] as List)
|
||||
.map((item) => TagModel.fromJson(item))
|
||||
.toList(),
|
||||
.map((item) => TagModel.fromJson(item))
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'uuid': uuid,
|
||||
'createdAt': createdAt.toIso8601String(),
|
||||
'updatedAt': updatedAt.toIso8601String(),
|
||||
'modelName': modelName,
|
||||
'disabled': disabled,
|
||||
'subspaceModels': subspaceModels.map((e) => e.toJson()).toList(),
|
||||
'tags': tags.map((e) => e.toJson()).toList(),
|
||||
'subspaceModels': subspaceModels?.map((e) => e.toJson()).toList(),
|
||||
'tags': tags?.map((e) => e.toJson()).toList(),
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -129,3 +118,75 @@ class TagModel {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class UpdateSubspaceTemplateModel {
|
||||
final String uuid;
|
||||
final Action action;
|
||||
final String? subspaceName;
|
||||
final List<UpdateTagModel>? tags;
|
||||
|
||||
UpdateSubspaceTemplateModel({
|
||||
required this.action,
|
||||
required this.uuid,
|
||||
this.subspaceName,
|
||||
this.tags,
|
||||
});
|
||||
|
||||
factory UpdateSubspaceTemplateModel.fromJson(Map<String, dynamic> json) {
|
||||
return UpdateSubspaceTemplateModel(
|
||||
action: ActionExtension.fromValue(json['action']),
|
||||
uuid: json['uuid'] ?? '',
|
||||
subspaceName: json['subspaceName'] ?? '',
|
||||
tags: (json['tags'] as List)
|
||||
.map((item) => UpdateTagModel.fromJson(item))
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'action': action.value,
|
||||
'uuid': uuid,
|
||||
'subspaceName': subspaceName,
|
||||
'tags': tags?.map((e) => e.toJson()).toList() ?? [],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class UpdateTagModel {
|
||||
final Action action;
|
||||
final String? uuid;
|
||||
final String tag;
|
||||
final bool disabled;
|
||||
final ProductModel? product;
|
||||
|
||||
UpdateTagModel({
|
||||
required this.action,
|
||||
this.uuid,
|
||||
required this.tag,
|
||||
required this.disabled,
|
||||
this.product,
|
||||
});
|
||||
|
||||
factory UpdateTagModel.fromJson(Map<String, dynamic> json) {
|
||||
return UpdateTagModel(
|
||||
action: ActionExtension.fromValue(json['action']),
|
||||
uuid: json['uuid'] ?? '',
|
||||
tag: json['tag'] ?? '',
|
||||
disabled: json['disabled'] ?? false,
|
||||
product: json['product'] != null
|
||||
? ProductModel.fromMap(json['product'])
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'action': action.value,
|
||||
'uuid': uuid,
|
||||
'tag': tag,
|
||||
'disabled': disabled,
|
||||
'product': product?.toMap(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user