From 072021bd4c466ea1d784fa949655ddf9f1002745 Mon Sep 17 00:00:00 2001 From: gelbeinhalb Date: Fri, 16 Jan 2026 10:50:03 +0100 Subject: [PATCH] update match class --- lib/data/dto/match.dart | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/data/dto/match.dart b/lib/data/dto/match.dart index 9570f66..c91dc92 100644 --- a/lib/data/dto/match.dart +++ b/lib/data/dto/match.dart @@ -1,4 +1,5 @@ import 'package:clock/clock.dart'; +import 'package:game_tracker/data/dto/game.dart'; import 'package:game_tracker/data/dto/group.dart'; import 'package:game_tracker/data/dto/player.dart'; import 'package:uuid/uuid.dart'; @@ -7,45 +8,49 @@ class Match { final String id; final DateTime createdAt; final String name; - final List? players; + final Game? game; final Group? group; - Player? winner; + final List? players; + final String? notes; Match({ String? id, DateTime? createdAt, required this.name, - this.players, + this.game, this.group, - this.winner, + this.players, + this.notes, }) : id = id ?? const Uuid().v4(), createdAt = createdAt ?? clock.now(); @override String toString() { - return 'Match{\n\tid: $id,\n\tname: $name,\n\tplayers: $players,\n\tgroup: $group,\n\twinner: $winner\n}'; + return 'Match{id: $id, name: $name, game: $game, group: $group, players: $players, notes: $notes}'; } /// Creates a Match instance from a JSON object. Match.fromJson(Map json) : id = json['id'], - name = json['name'], createdAt = DateTime.parse(json['createdAt']), + name = json['name'], + game = json['game'] != null ? Game.fromJson(json['game']) : null, + group = json['group'] != null ? Group.fromJson(json['group']) : null, players = json['players'] != null ? (json['players'] as List) - .map((playerJson) => Player.fromJson(playerJson)) - .toList() + .map((playerJson) => Player.fromJson(playerJson)) + .toList() : null, - group = json['group'] != null ? Group.fromJson(json['group']) : null, - winner = json['winner'] != null ? Player.fromJson(json['winner']) : null; + notes = json['notes']; /// Converts the Match instance to a JSON object. Map toJson() => { 'id': id, 'createdAt': createdAt.toIso8601String(), 'name': name, - 'players': players?.map((player) => player.toJson()).toList(), + 'game': game?.toJson(), 'group': group?.toJson(), - 'winner': winner?.toJson(), + 'players': players?.map((player) => player.toJson()).toList(), + 'notes': notes, }; }