Bearbeiten und Löschen von Gruppen #148

Merged
sneeex merged 20 commits from feature/118-bearbeiten-und-löschen-von-gruppen into development 2026-03-09 20:30:38 +00:00
2 changed files with 58 additions and 0 deletions
Showing only changes of commit 6c50eaefc7 - Show all commits

View File

@@ -338,6 +338,17 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
return rowsAffected > 0;
}
/// Entfernt die Gruppen-Verknüpfung des Matches mit der gegebenen [matchId].
sneeex marked this conversation as resolved Outdated

Kommentar auf Deutsch

Kommentar auf Deutsch
/// Setzt die groupId auf null.
/// Gibt `true` zurück, wenn mehr als 0 Zeilen betroffen waren, ansonsten `false`.
Future<bool> deleteMatchGroup({required String matchId}) async {
flixcoo marked this conversation as resolved Outdated

Methode lieber sowas nennen removeGroupFromMatch da hier ja keine keine Gruppe gelöscht wird

Methode lieber sowas nennen `removeGroupFromMatch` da hier ja keine keine Gruppe gelöscht wird
final query = update(matchTable)..where((g) => g.id.equals(matchId));
final rowsAffected = await query.write(
const MatchTableCompanion(groupId: Value(null)),
);
return rowsAffected > 0;
}
/// Updates the createdAt timestamp of the match with the given [matchId].
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
Future<bool> updateMatchCreatedAt({

View File

@@ -307,5 +307,52 @@ void main() {
expect(fetchedMatch.winner, isNotNull);
expect(fetchedMatch.winner!.id, testPlayer5.id);
});
// Tests for removeMatchGroup
sneeex marked this conversation as resolved
Review

Unnötiger Kommentar

Unnötiger Kommentar
test(
'removeMatchGroup removes group from match with existing group',
() async {
await database.matchDao.addMatch(match: testMatch1);
final removed = await database.matchDao.deleteMatchGroup(
matchId: testMatch1.id,
);
expect(removed, isTrue);
final updatedMatch = await database.matchDao.getMatchById(
matchId: testMatch1.id,
);
expect(updatedMatch.group, null);
// Andere Felder bleiben unverändert
sneeex marked this conversation as resolved
Review

Unnötiger Kommentar & auf deutsch

Unnötiger Kommentar & auf deutsch
expect(updatedMatch.game.id, testMatch1.game.id);
expect(updatedMatch.name, testMatch1.name);
expect(updatedMatch.notes, testMatch1.notes);
},
);
test(
'removeMatchGroup on match that already has no group still succeeds',
() async {
await database.matchDao.addMatch(match: testMatchOnlyPlayers);
final removed = await database.matchDao.deleteMatchGroup(
matchId: testMatchOnlyPlayers.id,
);
// Update sollte trotzdem eine Zeile betreffen
sneeex marked this conversation as resolved
Review

Unnötiger Kommentar & auf deutsch

Unnötiger Kommentar & auf deutsch
expect(removed, isTrue);
final updatedMatch = await database.matchDao.getMatchById(
matchId: testMatchOnlyPlayers.id,
);
expect(updatedMatch.group, null);
},
);
test('removeMatchGroup on non-existing match returns false', () async {
final removed = await database.matchDao.deleteMatchGroup(
matchId: 'non-existing-id',
);
expect(removed, isFalse);
});
});
}