Added missing score import

This commit is contained in:
2026-04-21 22:13:55 +02:00
parent b0a8529c1c
commit b1abbf6376
2 changed files with 40 additions and 6 deletions

View File

@@ -130,6 +130,7 @@ class MatchDao extends DatabaseAccessor<AppDatabase> 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<AppDatabase> 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<AppDatabase> with _$MatchDaoMixin {
),
);
// Add all matches in batch
// Add matches
await db.batch(
(b) => b.insertAll(
matchTable,
@@ -192,7 +193,7 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
),
);
// Add all players of the matches in batch (unique)
// Add players
final uniquePlayers = <String, Player>{};
for (final match in matches) {
for (final p in match.players) {
@@ -225,7 +226,27 @@ class MatchDao extends DatabaseAccessor<AppDatabase> 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<AppDatabase> 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) {

View File

@@ -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<String, dynamic>? ?? {};
final scores = scoresJson.map(
(key, value) => MapEntry(
key,
value != null
? ScoreEntry.fromJson(value as Map<String, dynamic>)
: 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();
}