Files
syncrow-web/lib/pages/spaces_management/model/community_model.dart
2024-10-08 11:39:10 +04:00

54 lines
1.5 KiB
Dart

import 'package:syncrow_web/pages/auth/model/region_model.dart';
import 'package:syncrow_web/pages/spaces_management/model/space_model.dart';
class CommunityModel {
final String uuid;
final DateTime createdAt;
final DateTime updatedAt;
final String name;
final String description;
final RegionModel? region;
List<SpaceModel> spaces;
CommunityModel({
required this.uuid,
required this.createdAt,
required this.updatedAt,
required this.name,
required this.description,
required this.spaces,
this.region,
});
factory CommunityModel.fromJson(Map<String, dynamic> json) {
return CommunityModel(
uuid: json['uuid'],
createdAt: DateTime.parse(json['createdAt']),
updatedAt: DateTime.parse(json['updatedAt']),
name: json['name'],
description: json['description'],
region:
json['region'] != null ? RegionModel.fromJson(json['region']) : null,
spaces: json['spaces'] != null
? (json['spaces'] as List)
.map((space) => SpaceModel.fromJson(space))
.toList()
: [],
);
}
Map<String, dynamic> toMap() {
return {
'uuid': uuid,
'createdAt': createdAt.toIso8601String(),
'updatedAt': updatedAt.toIso8601String(),
'name': name,
'description': description,
'region': region?.toJson(),
'spaces': spaces
.map((space) => space.toMap())
.toList(), // Convert spaces to Map
};
}
}