From b1abbf63766a232acd43154dae5ff73d97848ca4 Mon Sep 17 00:00:00 2001 From: Felix Kirchner Date: Tue, 21 Apr 2026 22:13:55 +0200 Subject: [PATCH] Added missing score import --- lib/data/dao/match_dao.dart | 31 +++++++++++++++++++++---- lib/services/data_transfer_service.dart | 15 +++++++++++- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/lib/data/dao/match_dao.dart b/lib/data/dao/match_dao.dart index 0b9300e..93df7d7 100644 --- a/lib/data/dao/match_dao.dart +++ b/lib/data/dao/match_dao.dart @@ -130,6 +130,7 @@ class MatchDao extends DatabaseAccessor with _$MatchDaoMixin { uniqueGames[match.game.id] = match.game; } + // Add games if (uniqueGames.isNotEmpty) { await db.batch( (b) => b.insertAll( @@ -152,7 +153,7 @@ class MatchDao extends DatabaseAccessor with _$MatchDaoMixin { ); } - // Add all groups of the matches in batch + // Add groups await db.batch( (b) => b.insertAll( db.groupTable, @@ -171,7 +172,7 @@ class MatchDao extends DatabaseAccessor with _$MatchDaoMixin { ), ); - // Add all matches in batch + // Add matches await db.batch( (b) => b.insertAll( matchTable, @@ -192,7 +193,7 @@ class MatchDao extends DatabaseAccessor with _$MatchDaoMixin { ), ); - // Add all players of the matches in batch (unique) + // Add players final uniquePlayers = {}; for (final match in matches) { for (final p in match.players) { @@ -225,7 +226,27 @@ class MatchDao extends DatabaseAccessor with _$MatchDaoMixin { ); } - // Add all player-match associations in batch + await db.batch((b) { + for (final match in matches) { + for (final entry in match.scores.entries) { + if (entry.value != null) { + b.insert( + db.scoreEntryTable, + ScoreEntryTableCompanion.insert( + matchId: match.id, + playerId: entry.key, + score: entry.value!.score, + roundNumber: entry.value!.roundNumber, + change: entry.value!.change, + ), + mode: InsertMode.insertOrReplace, + ); + } + } + } + }); + + // Add player-match associations await db.batch((b) { for (final match in matches) { for (final p in match.players) { @@ -241,7 +262,7 @@ class MatchDao extends DatabaseAccessor with _$MatchDaoMixin { } }); - // Add all player-group associations in batch + // Add player-group associations await db.batch((b) { for (final match in matches) { if (match.group != null) { diff --git a/lib/services/data_transfer_service.dart b/lib/services/data_transfer_service.dart index 05896ea..3203272 100644 --- a/lib/services/data_transfer_service.dart +++ b/lib/services/data_transfer_service.dart @@ -12,6 +12,7 @@ import 'package:tallee/data/models/game.dart'; import 'package:tallee/data/models/group.dart'; import 'package:tallee/data/models/match.dart'; import 'package:tallee/data/models/player.dart'; +import 'package:tallee/data/models/score_entry.dart'; import 'package:tallee/data/models/team.dart'; class DataTransferService { @@ -71,7 +72,9 @@ class DataTransferService { 'gameId': m.game.id, 'groupId': m.group?.id, 'playerIds': m.players.map((p) => p.id).toList(), - 'scores': m.scores, + 'scores': m.scores.map( + (key, value) => MapEntry(key, value?.toJson()), + ), 'notes': m.notes, }, ) @@ -271,6 +274,15 @@ class DataTransferService { ? DateTime.parse(map['endedAt'] as String) : null; final notes = map['notes'] as String? ?? ''; + final scoresJson = map['scores'] as Map? ?? {}; + final scores = scoresJson.map( + (key, value) => MapEntry( + key, + value != null + ? ScoreEntry.fromJson(value as Map) + : null, + ), + ); // Link attributes to objects final game = gamesMap[gameId] ?? getFallbackGame(); @@ -292,6 +304,7 @@ class DataTransferService { createdAt: createdAt, endedAt: endedAt, notes: notes, + scores: scores, ); }).toList(); }