feat: Refactor account handling and improve group creation logic
This commit is contained in:
@@ -1,53 +1,61 @@
|
||||
import 'dart:convert';
|
||||
import 'group_member.dart';
|
||||
|
||||
class Account {
|
||||
final String id;
|
||||
final String tripId;
|
||||
final String groupId;
|
||||
final String name;
|
||||
final DateTime createdAt;
|
||||
final DateTime updatedAt;
|
||||
final List<GroupMember> members;
|
||||
|
||||
Account({
|
||||
required this.id,
|
||||
required this.tripId,
|
||||
required this.groupId,
|
||||
required this.name,
|
||||
DateTime? createdAt,
|
||||
DateTime? updatedAt,
|
||||
List<GroupMember>? members,
|
||||
}) : members = members ?? [];
|
||||
}) : createdAt = createdAt ?? DateTime.now(),
|
||||
updatedAt = updatedAt ?? DateTime.now(),
|
||||
members = members ?? [];
|
||||
|
||||
|
||||
factory Account.fromMap(Map<String, dynamic> map) {
|
||||
factory Account.fromMap(Map<String, dynamic> map, String id) {
|
||||
return Account(
|
||||
id: map['id'] as String,
|
||||
tripId: map['tripId'] as String,
|
||||
groupId: map['groupId'] as String,
|
||||
name: map['name'] as String,
|
||||
id: id,
|
||||
tripId: map['tripId'] ?? '',
|
||||
name: map['name'] ?? '',
|
||||
createdAt: DateTime.fromMillisecondsSinceEpoch(map['createdAt'] ?? 0),
|
||||
updatedAt: DateTime.fromMillisecondsSinceEpoch(map['updatedAt'] ?? 0),
|
||||
members: [],
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'id': id,
|
||||
'tripId': tripId,
|
||||
'groupId': groupId,
|
||||
'name': name,
|
||||
'members': members.map((member) => member.toMap()).toList(),
|
||||
'createdAt': createdAt.millisecondsSinceEpoch,
|
||||
'updatedAt': updatedAt.millisecondsSinceEpoch,
|
||||
};
|
||||
}
|
||||
|
||||
String toJson() => json.encode(toMap());
|
||||
|
||||
Account copyWith({
|
||||
String? id,
|
||||
String? tripId,
|
||||
String? groupId,
|
||||
String? name,
|
||||
DateTime? createdAt,
|
||||
DateTime? updatedAt,
|
||||
List<GroupMember>? members,
|
||||
}) {
|
||||
return Account(
|
||||
id: id ?? this.id,
|
||||
tripId: tripId ?? this.tripId,
|
||||
groupId: groupId ?? this.groupId,
|
||||
name: name ?? this.name,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
updatedAt: updatedAt ?? this.updatedAt,
|
||||
members: members ?? this.members,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user