simplified json map
This commit is contained in:
@@ -37,48 +37,12 @@ class DataTransferService {
|
|||||||
final games = await db.gameDao.getAllGames();
|
final games = await db.gameDao.getAllGames();
|
||||||
final teams = await db.teamDao.getAllTeams();
|
final teams = await db.teamDao.getAllTeams();
|
||||||
|
|
||||||
// Construct a JSON representation of the data in normalized format
|
|
||||||
final Map<String, dynamic> jsonMap = {
|
final Map<String, dynamic> jsonMap = {
|
||||||
'players': players.map((p) => p.toJson()).toList(),
|
'players': players.map((player) => player.toJson()).toList(),
|
||||||
'games': games.map((g) => g.toJson()).toList(),
|
'games': games.map((game) => game.toJson()).toList(),
|
||||||
'groups': groups
|
'groups': groups.map((group) => group.toJson()).toList(),
|
||||||
.map(
|
'teams': teams.map((team) => team.toJson()).toList(),
|
||||||
(g) => {
|
'matches': matches.map((match) => match.toJson()).toList(),
|
||||||
'id': g.id,
|
|
||||||
'name': g.name,
|
|
||||||
'description': g.description,
|
|
||||||
'createdAt': g.createdAt.toIso8601String(),
|
|
||||||
'memberIds': (g.members).map((m) => m.id).toList(),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.toList(),
|
|
||||||
'teams': teams
|
|
||||||
.map(
|
|
||||||
(t) => {
|
|
||||||
'id': t.id,
|
|
||||||
'name': t.name,
|
|
||||||
'createdAt': t.createdAt.toIso8601String(),
|
|
||||||
'memberIds': (t.members).map((m) => m.id).toList(),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.toList(),
|
|
||||||
'matches': matches
|
|
||||||
.map(
|
|
||||||
(m) => {
|
|
||||||
'id': m.id,
|
|
||||||
'name': m.name,
|
|
||||||
'createdAt': m.createdAt.toIso8601String(),
|
|
||||||
'endedAt': m.endedAt?.toIso8601String(),
|
|
||||||
'gameId': m.game.id,
|
|
||||||
'groupId': m.group?.id,
|
|
||||||
'playerIds': m.players.map((p) => p.id).toList(),
|
|
||||||
'scores': m.scores.map(
|
|
||||||
(key, value) => MapEntry(key, value?.toJson()),
|
|
||||||
),
|
|
||||||
'notes': m.notes,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.toList(),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return json.encode(jsonMap);
|
return json.encode(jsonMap);
|
||||||
|
|||||||
Reference in New Issue
Block a user