Files
game-tracker/lib/data/dto/group.dart
gelbeinhalb be01b5f72a
Some checks failed
Pull Request Pipeline / lint (pull_request) Failing after 2m10s
Pull Request Pipeline / test (pull_request) Failing after 2m29s
add description to group
2026-01-12 12:51:25 +01:00

45 lines
1.2 KiB
Dart

import 'package:clock/clock.dart';
import 'package:game_tracker/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,
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.
Group.fromJson(Map<String, dynamic> json)
: id = json['id'],
createdAt = DateTime.parse(json['createdAt']),
name = json['name'],
description = json['description'],
members = (json['members'] as List)
.map((memberJson) => Player.fromJson(memberJson))
.toList();
/// Converts the Group instance to a JSON object.
Map<String, dynamic> toJson() => {
'id': id,
'createdAt': createdAt.toIso8601String(),
'name': name,
'description': description,
'members': members.map((member) => member.toJson()).toList(),
};
}