From 6a49b92310b4e3f3470cbf1fff9d0d5e1916dc5e Mon Sep 17 00:00:00 2001 From: Felix Kirchner Date: Wed, 8 Apr 2026 23:22:41 +0200 Subject: [PATCH] Moved dao methods --- lib/data/dao/player_match_dao.dart | 16 ---------- lib/data/dao/score_dao.dart | 10 +++--- test/db_tests/aggregates/match_test.dart | 1 - .../relationships/player_match_test.dart | 31 ++++++++++++------- 4 files changed, 24 insertions(+), 34 deletions(-) diff --git a/lib/data/dao/player_match_dao.dart b/lib/data/dao/player_match_dao.dart index 9be638c..36a7dbe 100644 --- a/lib/data/dao/player_match_dao.dart +++ b/lib/data/dao/player_match_dao.dart @@ -44,22 +44,6 @@ class PlayerMatchDao extends DatabaseAccessor return players; } - /// Updates the score for a player in a match. - /// Returns `true` if the update was successful, otherwise `false`. - Future updatePlayerScore({ - required String matchId, - required String playerId, - required int newScore, - }) async { - /* final rowsAffected = - await (update(playerMatchTable)..where( - (p) => p.matchId.equals(matchId) & p.playerId.equals(playerId), - )) - .write(PlayerMatchTableCompanion(score: Value(newScore))); - return rowsAffected > 0;*/ - return false; - } - /// Updates the team for a player in a match. /// Returns `true` if the update was successful, otherwise `false`. Future updatePlayerTeam({ diff --git a/lib/data/dao/score_dao.dart b/lib/data/dao/score_dao.dart index bafb8e0..2d454ed 100644 --- a/lib/data/dao/score_dao.dart +++ b/lib/data/dao/score_dao.dart @@ -14,9 +14,9 @@ class ScoreDao extends DatabaseAccessor with _$ScoreDaoMixin { Future addScore({ required String playerId, required String matchId, - required int roundNumber, required int score, - required int change, + int change = 0, + int roundNumber = 0, }) async { await into(scoreTable).insert( ScoreTableCompanion.insert( @@ -97,9 +97,9 @@ class ScoreDao extends DatabaseAccessor with _$ScoreDaoMixin { Future updateScore({ required String playerId, required String matchId, - required int roundNumber, required int newScore, - required int newChange, + int newChange = 0, + int roundNumber = 0, }) async { final rowsAffected = await (update(scoreTable)..where( @@ -121,7 +121,7 @@ class ScoreDao extends DatabaseAccessor with _$ScoreDaoMixin { Future deleteScore({ required String playerId, required String matchId, - required int roundNumber, + int roundNumber = 0, }) async { final query = delete(scoreTable) ..where( diff --git a/test/db_tests/aggregates/match_test.dart b/test/db_tests/aggregates/match_test.dart index 59a13af..e2cc72f 100644 --- a/test/db_tests/aggregates/match_test.dart +++ b/test/db_tests/aggregates/match_test.dart @@ -360,7 +360,6 @@ void main() { expect(matches, isEmpty); await database.matchDao.addMatch(match: testMatch1); - print(await database.matchDao.getAllMatches()); matches = await database.matchDao.getGroupMatches(groupId: testGroup1.id); diff --git a/test/db_tests/relationships/player_match_test.dart b/test/db_tests/relationships/player_match_test.dart index d085096..a1abcb7 100644 --- a/test/db_tests/relationships/player_match_test.dart +++ b/test/db_tests/relationships/player_match_test.dart @@ -349,7 +349,7 @@ void main() { () async { await database.matchDao.addMatch(match: testMatchOnlyGroup); - final updated = await database.playerMatchDao.updatePlayerScore( + final updated = await database.scoreDao.updateScore( matchId: testMatchOnlyGroup.id, playerId: 'non-existent-player-id', newScore: 50, @@ -611,7 +611,7 @@ void main() { await database.matchDao.addMatch(match: testMatchOnlyPlayers); // Update score for existing player - await database.playerMatchDao.updatePlayerScore( + await database.scoreDao.updateScore( matchId: testMatchOnlyPlayers.id, playerId: testPlayer4.id, newScore: 75, @@ -623,6 +623,7 @@ void main() { newPlayer: [testPlayer4, testPlayer1], ); + // TODO: Fix /*// Verify testPlayer4's score is preserved final score = await database.playerMatchDao.getPlayerScore( matchId: testMatchOnlyPlayers.id, @@ -649,9 +650,9 @@ void main() { matchId: testMatchOnlyGroup.id, playerId: testPlayer1.id, teamId: testTeam1.id, - score: 150, ); + // TODO: fix /*// Verify score final score = await database.playerMatchDao.getPlayerScore( matchId: testMatchOnlyGroup.id, @@ -671,8 +672,13 @@ void main() { // Verifies that updating score with negative value works. test('updatePlayerScore with negative score works', () async { await database.matchDao.addMatch(match: testMatchOnlyPlayers); + await database.scoreDao.addScore( + playerId: testPlayer4.id, + matchId: testMatchOnlyPlayers.id, + score: 0, + ); - final updated = await database.playerMatchDao.updatePlayerScore( + final updated = await database.scoreDao.updateScore( matchId: testMatchOnlyPlayers.id, playerId: testPlayer4.id, newScore: -10, @@ -680,6 +686,7 @@ void main() { expect(updated, true); + // TODO: fix /* final score = await database.playerMatchDao.getPlayerScore( matchId: testMatchOnlyPlayers.id, playerId: testPlayer4.id, @@ -691,16 +698,14 @@ void main() { // Verifies that updating score with zero value works. test('updatePlayerScore with zero score works', () async { await database.matchDao.addMatch(match: testMatchOnlyPlayers); - - // First set a non-zero score - await database.playerMatchDao.updatePlayerScore( - matchId: testMatchOnlyPlayers.id, + await database.scoreDao.addScore( playerId: testPlayer4.id, - newScore: 100, + matchId: testMatchOnlyPlayers.id, + score: 100, ); // Then update to zero - final updated = await database.playerMatchDao.updatePlayerScore( + final updated = await database.scoreDao.updateScore( matchId: testMatchOnlyPlayers.id, playerId: testPlayer4.id, newScore: 0, @@ -708,6 +713,7 @@ void main() { expect(updated, true); + // TODO: Fix /*final score = await database.playerMatchDao.getPlayerScore( matchId: testMatchOnlyPlayers.id, playerId: testPlayer4.id, @@ -839,19 +845,20 @@ void main() { ]); // Update score in match1 - await database.playerMatchDao.updatePlayerScore( + await database.scoreDao.updateScore( matchId: match1.id, playerId: testPlayer1.id, newScore: 100, ); // Update score in match2 - await database.playerMatchDao.updatePlayerScore( + await database.scoreDao.updateScore( matchId: match2.id, playerId: testPlayer1.id, newScore: 50, ); + // TODO: fix /* // Verify scores are independent final scoreInMatch1 = await database.playerMatchDao.getPlayerScore( matchId: match1.id,