# Conflicts: # lib/data/dao/group_match_dao.dart # lib/data/dao/match_dao.dart # lib/data/dao/player_match_dao.dart # lib/data/db/database.dart # lib/data/db/database.g.dart # lib/data/db/tables/group_match_table.dart # lib/data/db/tables/player_match_table.dart # lib/data/dto/match.dart # lib/presentation/views/main_menu/home_view.dart # lib/presentation/views/main_menu/match_view/create_match/create_match_view.dart # lib/presentation/views/main_menu/match_view/match_view.dart # lib/services/data_transfer_service.dart # test/db_tests/game_test.dart # test/db_tests/group_match_test.dart # test/db_tests/player_match_test.dart
44 lines
1.3 KiB
Dart
44 lines
1.3 KiB
Dart
import 'package:clock/clock.dart';
|
|
import 'package:tallee/data/dto/player.dart';
|
|
import 'package:uuid/uuid.dart';
|
|
|
|
class Group {
|
|
final String id;
|
|
final String name;
|
|
final String description;
|
|
final DateTime createdAt;
|
|
final List<Player> members;
|
|
|
|
Group({
|
|
String? id,
|
|
DateTime? createdAt,
|
|
required this.name,
|
|
required this.description,
|
|
required this.members,
|
|
}) : id = id ?? const Uuid().v4(),
|
|
createdAt = createdAt ?? clock.now();
|
|
|
|
@override
|
|
String toString() {
|
|
return 'Group{id: $id, name: $name, description: $description, members: $members}';
|
|
}
|
|
|
|
/// Creates a Group instance from a JSON object (memberIds format).
|
|
/// Player objects are reconstructed from memberIds by the DataTransferService.
|
|
Group.fromJson(Map<String, dynamic> json)
|
|
: id = json['id'],
|
|
createdAt = DateTime.parse(json['createdAt']),
|
|
name = json['name'],
|
|
description = json['description'],
|
|
members = []; // Populated during import via DataTransferService
|
|
|
|
/// Converts the Group instance to a JSON object using normalized format (memberIds only).
|
|
Map<String, dynamic> toJson() => {
|
|
'id': id,
|
|
'createdAt': createdAt.toIso8601String(),
|
|
'name': name,
|
|
'description': description,
|
|
'memberIds': members.map((member) => member.id).toList(),
|
|
};
|
|
}
|