Added updateGroupOfGame(), added docc & tests

This commit is contained in:
2025-11-26 14:17:11 +01:00
parent 738f242eee
commit 397c5c1550
3 changed files with 91 additions and 20 deletions

View File

@@ -11,8 +11,12 @@ class GroupGameDao extends DatabaseAccessor<AppDatabase>
GroupGameDao(super.db);
/// Associates a group with a game by inserting a record into the
/// [GroupGameTable].
Future<void> addGroupToGame(String gameId, String groupId) async {
/// [GroupGameTable]. If there is already group associated to the game,
/// it will be replaced.
Future<void> addGroupToGame({
required String gameId,
required String groupId,
}) async {
await into(groupGameTable).insert(
GroupGameTableCompanion.insert(groupId: groupId, gameId: gameId),
mode: InsertMode.insertOrReplace,
@@ -76,4 +80,17 @@ class GroupGameDao extends DatabaseAccessor<AppDatabase>
final rowsAffected = await query.go();
return rowsAffected > 0;
}
/// Updates the group associated with a game to [newGroupId] based on
/// [gameId].
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
Future<bool> updateGroupOfGame({
required String gameId,
required String newGroupId,
}) async {
final updatedRows =
await (update(groupGameTable)..where((g) => g.gameId.equals(gameId)))
.write(GroupGameTableCompanion(groupId: Value(newGroupId)));
return updatedRows > 0;
}
}