Datenbankkorrekturen #25

Merged
flixcoo merged 7 commits from enhancement/24-datenbankkorrekturen into development 2025-11-16 20:57:40 +00:00
Showing only changes of commit 5c09dfb47d - Show all commits

View File

@@ -38,28 +38,32 @@ class GroupDao extends DatabaseAccessor<AppDatabase> with _$GroupDaoMixin {
/// Adds a new group with the given [id] and [name] to the database. /// Adds a new group with the given [id] and [name] to the database.
/// This method also adds the group's members to the [PlayerGroupTable]. /// This method also adds the group's members to the [PlayerGroupTable].
Future<void> addGroup({required Group group}) async { Future<bool> addGroup({required Group group}) async {
await db.transaction(() async { if (!await groupExists(groupId: group.id)) {
await into( await db.transaction(() async {
groupTable, await into(
).insert(GroupTableCompanion.insert(id: group.id, name: group.name)); groupTable,
await db.batch( ).insert(GroupTableCompanion.insert(id: group.id, name: group.name));
(b) => b.insertAll( await db.batch(
db.playerGroupTable, (b) => b.insertAll(
group.members db.playerGroupTable,
.map( group.members
(member) => PlayerGroupTableCompanion.insert( .map(
playerId: member.id, (member) => PlayerGroupTableCompanion.insert(
groupId: group.id, playerId: member.id,
), groupId: group.id,
) ),
.toList(), )
), .toList(),
); ),
await Future.wait( );
group.members.map((player) => db.playerDao.addPlayer(player: player)), await Future.wait(
); group.members.map((player) => db.playerDao.addPlayer(player: player)),
}); );
return true;
});
}
return false;
} }
/// Deletes the group with the given [id] from the database. /// Deletes the group with the given [id] from the database.