Moved dao methods

This commit is contained in:
2026-04-08 23:22:41 +02:00
parent 855b7c8bea
commit 6a49b92310
4 changed files with 24 additions and 34 deletions

View File

@@ -44,22 +44,6 @@ class PlayerMatchDao extends DatabaseAccessor<AppDatabase>
return players;
}
/// Updates the score for a player in a match.
/// Returns `true` if the update was successful, otherwise `false`.
Future<bool> 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<bool> updatePlayerTeam({

View File

@@ -14,9 +14,9 @@ class ScoreDao extends DatabaseAccessor<AppDatabase> with _$ScoreDaoMixin {
Future<void> 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<AppDatabase> with _$ScoreDaoMixin {
Future<bool> 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<AppDatabase> with _$ScoreDaoMixin {
Future<bool> deleteScore({
required String playerId,
required String matchId,
required int roundNumber,
int roundNumber = 0,
}) async {
final query = delete(scoreTable)
..where(

View File

@@ -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);

View File

@@ -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,