Added missing score import
This commit is contained in:
@@ -130,6 +130,7 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
|||||||
uniqueGames[match.game.id] = match.game;
|
uniqueGames[match.game.id] = match.game;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add games
|
||||||
if (uniqueGames.isNotEmpty) {
|
if (uniqueGames.isNotEmpty) {
|
||||||
await db.batch(
|
await db.batch(
|
||||||
(b) => b.insertAll(
|
(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(
|
await db.batch(
|
||||||
(b) => b.insertAll(
|
(b) => b.insertAll(
|
||||||
db.groupTable,
|
db.groupTable,
|
||||||
@@ -171,7 +172,7 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Add all matches in batch
|
// Add matches
|
||||||
await db.batch(
|
await db.batch(
|
||||||
(b) => b.insertAll(
|
(b) => b.insertAll(
|
||||||
matchTable,
|
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>{};
|
final uniquePlayers = <String, Player>{};
|
||||||
for (final match in matches) {
|
for (final match in matches) {
|
||||||
for (final p in match.players) {
|
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) {
|
await db.batch((b) {
|
||||||
for (final match in matches) {
|
for (final match in matches) {
|
||||||
for (final p in match.players) {
|
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) {
|
await db.batch((b) {
|
||||||
for (final match in matches) {
|
for (final match in matches) {
|
||||||
if (match.group != null) {
|
if (match.group != null) {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import 'package:tallee/data/models/game.dart';
|
|||||||
import 'package:tallee/data/models/group.dart';
|
import 'package:tallee/data/models/group.dart';
|
||||||
import 'package:tallee/data/models/match.dart';
|
import 'package:tallee/data/models/match.dart';
|
||||||
import 'package:tallee/data/models/player.dart';
|
import 'package:tallee/data/models/player.dart';
|
||||||
|
import 'package:tallee/data/models/score_entry.dart';
|
||||||
import 'package:tallee/data/models/team.dart';
|
import 'package:tallee/data/models/team.dart';
|
||||||
|
|
||||||
class DataTransferService {
|
class DataTransferService {
|
||||||
@@ -71,7 +72,9 @@ class DataTransferService {
|
|||||||
'gameId': m.game.id,
|
'gameId': m.game.id,
|
||||||
'groupId': m.group?.id,
|
'groupId': m.group?.id,
|
||||||
'playerIds': m.players.map((p) => p.id).toList(),
|
'playerIds': m.players.map((p) => p.id).toList(),
|
||||||
'scores': m.scores,
|
'scores': m.scores.map(
|
||||||
|
(key, value) => MapEntry(key, value?.toJson()),
|
||||||
|
),
|
||||||
'notes': m.notes,
|
'notes': m.notes,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -271,6 +274,15 @@ class DataTransferService {
|
|||||||
? DateTime.parse(map['endedAt'] as String)
|
? DateTime.parse(map['endedAt'] as String)
|
||||||
: null;
|
: null;
|
||||||
final notes = map['notes'] as String? ?? '';
|
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
|
// Link attributes to objects
|
||||||
final game = gamesMap[gameId] ?? getFallbackGame();
|
final game = gamesMap[gameId] ?? getFallbackGame();
|
||||||
@@ -292,6 +304,7 @@ class DataTransferService {
|
|||||||
createdAt: createdAt,
|
createdAt: createdAt,
|
||||||
endedAt: endedAt,
|
endedAt: endedAt,
|
||||||
notes: notes,
|
notes: notes,
|
||||||
|
scores: scores,
|
||||||
);
|
);
|
||||||
}).toList();
|
}).toList();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user