WIP: Score implementation ergänzen #196
@@ -44,22 +44,6 @@ class PlayerMatchDao extends DatabaseAccessor<AppDatabase>
|
|||||||
return players;
|
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.
|
/// Updates the team for a player in a match.
|
||||||
/// Returns `true` if the update was successful, otherwise `false`.
|
/// Returns `true` if the update was successful, otherwise `false`.
|
||||||
Future<bool> updatePlayerTeam({
|
Future<bool> updatePlayerTeam({
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ class ScoreDao extends DatabaseAccessor<AppDatabase> with _$ScoreDaoMixin {
|
|||||||
Future<void> addScore({
|
Future<void> addScore({
|
||||||
required String playerId,
|
required String playerId,
|
||||||
required String matchId,
|
required String matchId,
|
||||||
required int roundNumber,
|
|
||||||
required int score,
|
required int score,
|
||||||
required int change,
|
int change = 0,
|
||||||
|
int roundNumber = 0,
|
||||||
}) async {
|
}) async {
|
||||||
await into(scoreTable).insert(
|
await into(scoreTable).insert(
|
||||||
ScoreTableCompanion.insert(
|
ScoreTableCompanion.insert(
|
||||||
@@ -97,9 +97,9 @@ class ScoreDao extends DatabaseAccessor<AppDatabase> with _$ScoreDaoMixin {
|
|||||||
Future<bool> updateScore({
|
Future<bool> updateScore({
|
||||||
required String playerId,
|
required String playerId,
|
||||||
required String matchId,
|
required String matchId,
|
||||||
required int roundNumber,
|
|
||||||
required int newScore,
|
required int newScore,
|
||||||
required int newChange,
|
int newChange = 0,
|
||||||
|
int roundNumber = 0,
|
||||||
}) async {
|
}) async {
|
||||||
final rowsAffected =
|
final rowsAffected =
|
||||||
await (update(scoreTable)..where(
|
await (update(scoreTable)..where(
|
||||||
@@ -121,7 +121,7 @@ class ScoreDao extends DatabaseAccessor<AppDatabase> with _$ScoreDaoMixin {
|
|||||||
Future<bool> deleteScore({
|
Future<bool> deleteScore({
|
||||||
required String playerId,
|
required String playerId,
|
||||||
required String matchId,
|
required String matchId,
|
||||||
required int roundNumber,
|
int roundNumber = 0,
|
||||||
}) async {
|
}) async {
|
||||||
final query = delete(scoreTable)
|
final query = delete(scoreTable)
|
||||||
..where(
|
..where(
|
||||||
|
|||||||
@@ -360,7 +360,6 @@ void main() {
|
|||||||
expect(matches, isEmpty);
|
expect(matches, isEmpty);
|
||||||
|
|
||||||
await database.matchDao.addMatch(match: testMatch1);
|
await database.matchDao.addMatch(match: testMatch1);
|
||||||
print(await database.matchDao.getAllMatches());
|
|
||||||
|
|
||||||
matches = await database.matchDao.getGroupMatches(groupId: testGroup1.id);
|
matches = await database.matchDao.getGroupMatches(groupId: testGroup1.id);
|
||||||
|
|
||||||
|
|||||||
@@ -349,7 +349,7 @@ void main() {
|
|||||||
() async {
|
() async {
|
||||||
await database.matchDao.addMatch(match: testMatchOnlyGroup);
|
await database.matchDao.addMatch(match: testMatchOnlyGroup);
|
||||||
|
|
||||||
final updated = await database.playerMatchDao.updatePlayerScore(
|
final updated = await database.scoreDao.updateScore(
|
||||||
matchId: testMatchOnlyGroup.id,
|
matchId: testMatchOnlyGroup.id,
|
||||||
playerId: 'non-existent-player-id',
|
playerId: 'non-existent-player-id',
|
||||||
newScore: 50,
|
newScore: 50,
|
||||||
@@ -611,7 +611,7 @@ void main() {
|
|||||||
await database.matchDao.addMatch(match: testMatchOnlyPlayers);
|
await database.matchDao.addMatch(match: testMatchOnlyPlayers);
|
||||||
|
|
||||||
// Update score for existing player
|
// Update score for existing player
|
||||||
await database.playerMatchDao.updatePlayerScore(
|
await database.scoreDao.updateScore(
|
||||||
matchId: testMatchOnlyPlayers.id,
|
matchId: testMatchOnlyPlayers.id,
|
||||||
playerId: testPlayer4.id,
|
playerId: testPlayer4.id,
|
||||||
newScore: 75,
|
newScore: 75,
|
||||||
@@ -623,6 +623,7 @@ void main() {
|
|||||||
newPlayer: [testPlayer4, testPlayer1],
|
newPlayer: [testPlayer4, testPlayer1],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// TODO: Fix
|
||||||
/*// Verify testPlayer4's score is preserved
|
/*// Verify testPlayer4's score is preserved
|
||||||
final score = await database.playerMatchDao.getPlayerScore(
|
final score = await database.playerMatchDao.getPlayerScore(
|
||||||
matchId: testMatchOnlyPlayers.id,
|
matchId: testMatchOnlyPlayers.id,
|
||||||
@@ -649,9 +650,9 @@ void main() {
|
|||||||
matchId: testMatchOnlyGroup.id,
|
matchId: testMatchOnlyGroup.id,
|
||||||
playerId: testPlayer1.id,
|
playerId: testPlayer1.id,
|
||||||
teamId: testTeam1.id,
|
teamId: testTeam1.id,
|
||||||
score: 150,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// TODO: fix
|
||||||
/*// Verify score
|
/*// Verify score
|
||||||
final score = await database.playerMatchDao.getPlayerScore(
|
final score = await database.playerMatchDao.getPlayerScore(
|
||||||
matchId: testMatchOnlyGroup.id,
|
matchId: testMatchOnlyGroup.id,
|
||||||
@@ -671,8 +672,13 @@ void main() {
|
|||||||
// Verifies that updating score with negative value works.
|
// Verifies that updating score with negative value works.
|
||||||
test('updatePlayerScore with negative score works', () async {
|
test('updatePlayerScore with negative score works', () async {
|
||||||
await database.matchDao.addMatch(match: testMatchOnlyPlayers);
|
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,
|
matchId: testMatchOnlyPlayers.id,
|
||||||
playerId: testPlayer4.id,
|
playerId: testPlayer4.id,
|
||||||
newScore: -10,
|
newScore: -10,
|
||||||
@@ -680,6 +686,7 @@ void main() {
|
|||||||
|
|
||||||
expect(updated, true);
|
expect(updated, true);
|
||||||
|
|
||||||
|
// TODO: fix
|
||||||
/* final score = await database.playerMatchDao.getPlayerScore(
|
/* final score = await database.playerMatchDao.getPlayerScore(
|
||||||
matchId: testMatchOnlyPlayers.id,
|
matchId: testMatchOnlyPlayers.id,
|
||||||
playerId: testPlayer4.id,
|
playerId: testPlayer4.id,
|
||||||
@@ -691,16 +698,14 @@ void main() {
|
|||||||
// Verifies that updating score with zero value works.
|
// Verifies that updating score with zero value works.
|
||||||
test('updatePlayerScore with zero score works', () async {
|
test('updatePlayerScore with zero score works', () async {
|
||||||
await database.matchDao.addMatch(match: testMatchOnlyPlayers);
|
await database.matchDao.addMatch(match: testMatchOnlyPlayers);
|
||||||
|
await database.scoreDao.addScore(
|
||||||
// First set a non-zero score
|
|
||||||
await database.playerMatchDao.updatePlayerScore(
|
|
||||||
matchId: testMatchOnlyPlayers.id,
|
|
||||||
playerId: testPlayer4.id,
|
playerId: testPlayer4.id,
|
||||||
newScore: 100,
|
matchId: testMatchOnlyPlayers.id,
|
||||||
|
score: 100,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Then update to zero
|
// Then update to zero
|
||||||
final updated = await database.playerMatchDao.updatePlayerScore(
|
final updated = await database.scoreDao.updateScore(
|
||||||
matchId: testMatchOnlyPlayers.id,
|
matchId: testMatchOnlyPlayers.id,
|
||||||
playerId: testPlayer4.id,
|
playerId: testPlayer4.id,
|
||||||
newScore: 0,
|
newScore: 0,
|
||||||
@@ -708,6 +713,7 @@ void main() {
|
|||||||
|
|
||||||
expect(updated, true);
|
expect(updated, true);
|
||||||
|
|
||||||
|
// TODO: Fix
|
||||||
/*final score = await database.playerMatchDao.getPlayerScore(
|
/*final score = await database.playerMatchDao.getPlayerScore(
|
||||||
matchId: testMatchOnlyPlayers.id,
|
matchId: testMatchOnlyPlayers.id,
|
||||||
playerId: testPlayer4.id,
|
playerId: testPlayer4.id,
|
||||||
@@ -839,19 +845,20 @@ void main() {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
// Update score in match1
|
// Update score in match1
|
||||||
await database.playerMatchDao.updatePlayerScore(
|
await database.scoreDao.updateScore(
|
||||||
matchId: match1.id,
|
matchId: match1.id,
|
||||||
playerId: testPlayer1.id,
|
playerId: testPlayer1.id,
|
||||||
newScore: 100,
|
newScore: 100,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Update score in match2
|
// Update score in match2
|
||||||
await database.playerMatchDao.updatePlayerScore(
|
await database.scoreDao.updateScore(
|
||||||
matchId: match2.id,
|
matchId: match2.id,
|
||||||
playerId: testPlayer1.id,
|
playerId: testPlayer1.id,
|
||||||
newScore: 50,
|
newScore: 50,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// TODO: fix
|
||||||
/* // Verify scores are independent
|
/* // Verify scores are independent
|
||||||
final scoreInMatch1 = await database.playerMatchDao.getPlayerScore(
|
final scoreInMatch1 = await database.playerMatchDao.getPlayerScore(
|
||||||
matchId: match1.id,
|
matchId: match1.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user