Refactor Space and Tag Models: Removed unused JSON serialization methods from SpaceDetailsModel, ProductAllocation, and Subspace. Updated Tag model to eliminate unnecessary fields. Enhanced UpdateSpaceParam to streamline JSON conversion for subspaces and product allocations, improving data handling during updates.

This commit is contained in:
Faris Armoush
2025-07-09 15:08:49 +03:00
parent 2b8d987c69
commit 5cd083a37b
7 changed files with 34 additions and 87 deletions

View File

@ -13,33 +13,29 @@ class UpdateSpaceParam {
return {
'spaceName': space.spaceName,
'icon': space.icon,
'subspaces': space.subspaces
.map(
(e) => {
'subspaceName': e.name,
'productAllocations': e.productAllocations
.map(
(e) => {
'name': e.tag.name,
'productUuid': e.product.uuid,
'uuid': e.uuid,
},
)
.toList(),
'uuid': e.uuid,
},
)
.toList(),
'productAllocations': space.productAllocations
.map(
(e) => {
'tagName': e.tag.name,
'tagUuid': e.tag.uuid,
'productUuid': e.product.uuid,
},
)
.toList(),
'spaceModelUuid': space.uuid,
'subspaces': space.subspaces.map((e) => e._toJson()).toList(),
'productAllocations':
space.productAllocations.map((e) => e._toJson()).toList(),
};
}
}
extension _ProductAllocationToJson on ProductAllocation {
Map<String, dynamic> _toJson() {
final isNewTag = tag.uuid.isEmpty;
return <String, dynamic>{
if (isNewTag) 'tagName': tag.name else 'tagUuid': tag.uuid,
'productUuid': product.uuid,
};
}
}
extension _SubspaceToJson on Subspace {
Map<String, dynamic> _toJson() {
final isNewSubspace = uuid.endsWith('-NewTag');
return <String, dynamic>{
if (isNewSubspace) 'subspaceName': name else 'uuid': uuid,
'productAllocations': productAllocations.map((e) => e._toJson()).toList(),
};
}
}