From ad6d08374e4c7c7d560e61164d96849dc8752f1b Mon Sep 17 00:00:00 2001 From: Felix Kirchner Date: Wed, 8 Apr 2026 22:27:50 +0200 Subject: [PATCH] Renamed folder to "models" --- lib/core/common.dart | 2 +- lib/data/dao/game_dao.dart | 49 ++-- lib/data/dao/game_dao.g.dart | 8 + lib/data/dao/group_dao.dart | 4 +- lib/data/dao/group_dao.g.dart | 19 ++ lib/data/dao/match_dao.dart | 8 +- lib/data/dao/match_dao.g.dart | 21 ++ lib/data/dao/player_dao.dart | 2 +- lib/data/dao/player_dao.g.dart | 8 + lib/data/dao/player_group_dao.dart | 2 +- lib/data/dao/player_group_dao.g.dart | 15 ++ lib/data/dao/player_match_dao.dart | 84 +++--- lib/data/dao/player_match_dao.g.dart | 21 ++ lib/data/dao/score_dao.dart | 2 +- lib/data/dao/score_dao.g.dart | 16 ++ lib/data/dao/team_dao.dart | 5 +- lib/data/dao/team_dao.g.dart | 8 + lib/data/db/database.g.dart | 114 ++------ lib/data/{dto => models}/game.dart | 0 lib/data/{dto => models}/group.dart | 2 +- lib/data/{dto => models}/match.dart | 8 +- lib/data/{dto => models}/player.dart | 0 lib/data/{dto => models}/score_entry.dart | 0 lib/data/{dto => models}/team.dart | 3 +- .../group_view/create_group_view.dart | 4 +- .../group_view/group_detail_view.dart | 6 +- .../main_menu/group_view/group_view.dart | 4 +- .../views/main_menu/home_view.dart | 66 +++-- .../create_match/choose_group_view.dart | 2 +- .../create_match/create_match_view.dart | 8 +- .../match_view/match_detail_view.dart | 2 +- .../match_view/match_result_view.dart | 4 +- .../main_menu/match_view/match_view.dart | 8 +- .../views/main_menu/statistics_view.dart | 18 +- .../widgets/player_selection.dart | 2 +- .../widgets/tiles/group_tile.dart | 2 +- .../widgets/tiles/match_tile.dart | 2 +- lib/services/data_transfer_service.dart | 112 +++++--- test/db_tests/aggregates/group_test.dart | 27 +- test/db_tests/aggregates/match_test.dart | 8 +- test/db_tests/aggregates/team_test.dart | 62 ++--- test/db_tests/entities/game_test.dart | 17 +- test/db_tests/entities/player_test.dart | 30 ++- .../relationships/player_group_test.dart | 206 ++++++++------ .../relationships/player_match_test.dart | 251 +++++++++++------- test/db_tests/values/score_test.dart | 122 +++++---- 46 files changed, 795 insertions(+), 569 deletions(-) rename lib/data/{dto => models}/game.dart (100%) rename lib/data/{dto => models}/group.dart (96%) rename lib/data/{dto => models}/match.dart (91%) rename lib/data/{dto => models}/player.dart (100%) rename lib/data/{dto => models}/score_entry.dart (100%) rename lib/data/{dto => models}/team.dart (95%) diff --git a/lib/core/common.dart b/lib/core/common.dart index a27daf0..20b0225 100644 --- a/lib/core/common.dart +++ b/lib/core/common.dart @@ -1,6 +1,6 @@ import 'package:flutter/cupertino.dart'; import 'package:tallee/core/enums.dart'; -import 'package:tallee/data/dto/match.dart'; +import 'package:tallee/data/models/match.dart'; import 'package:tallee/l10n/generated/app_localizations.dart'; /// Translates a [Ruleset] enum value to its corresponding localized string. diff --git a/lib/data/dao/game_dao.dart b/lib/data/dao/game_dao.dart index 8e658ed..f07e2c7 100644 --- a/lib/data/dao/game_dao.dart +++ b/lib/data/dao/game_dao.dart @@ -1,8 +1,8 @@ import 'package:drift/drift.dart'; +import 'package:tallee/core/enums.dart'; import 'package:tallee/data/db/database.dart'; import 'package:tallee/data/db/tables/game_table.dart'; -import 'package:tallee/data/dto/game.dart'; -import 'package:tallee/core/enums.dart'; +import 'package:tallee/data/models/game.dart'; part 'game_dao.g.dart'; @@ -111,14 +111,20 @@ class GameDao extends DatabaseAccessor with _$GameDaoMixin { } /// Updates the name of the game with the given [gameId] to [newName]. - Future updateGameName({required String gameId, required String newName}) async { - await (update( - gameTable, - )..where((g) => g.id.equals(gameId))).write(GameTableCompanion(name: Value(newName))); + Future updateGameName({ + required String gameId, + required String newName, + }) async { + await (update(gameTable)..where((g) => g.id.equals(gameId))).write( + GameTableCompanion(name: Value(newName)), + ); } /// Updates the ruleset of the game with the given [gameId]. - Future updateGameRuleset({required String gameId, required Ruleset newRuleset}) async { + Future updateGameRuleset({ + required String gameId, + required Ruleset newRuleset, + }) async { await (update(gameTable)..where((g) => g.id.equals(gameId))).write( GameTableCompanion(ruleset: Value(newRuleset.name)), ); @@ -135,24 +141,31 @@ class GameDao extends DatabaseAccessor with _$GameDaoMixin { } /// Updates the color of the game with the given [gameId]. - Future updateGameColor({required String gameId, required GameColor newColor}) async { - await (update( - gameTable, - )..where((g) => g.id.equals(gameId))).write(GameTableCompanion(color: Value(newColor.name))); + Future updateGameColor({ + required String gameId, + required GameColor newColor, + }) async { + await (update(gameTable)..where((g) => g.id.equals(gameId))).write( + GameTableCompanion(color: Value(newColor.name)), + ); } /// Updates the icon of the game with the given [gameId]. - Future updateGameIcon({required String gameId, required String newIcon}) async { - await (update( - gameTable, - )..where((g) => g.id.equals(gameId))).write(GameTableCompanion(icon: Value(newIcon))); + Future updateGameIcon({ + required String gameId, + required String newIcon, + }) async { + await (update(gameTable)..where((g) => g.id.equals(gameId))).write( + GameTableCompanion(icon: Value(newIcon)), + ); } /// Retrieves the total count of games in the database. Future getGameCount() async { - final count = await (selectOnly( - gameTable, - )..addColumns([gameTable.id.count()])).map((row) => row.read(gameTable.id.count())).getSingle(); + final count = + await (selectOnly(gameTable)..addColumns([gameTable.id.count()])) + .map((row) => row.read(gameTable.id.count())) + .getSingle(); return count ?? 0; } diff --git a/lib/data/dao/game_dao.g.dart b/lib/data/dao/game_dao.g.dart index b5a29fe..a998fe7 100644 --- a/lib/data/dao/game_dao.g.dart +++ b/lib/data/dao/game_dao.g.dart @@ -5,4 +5,12 @@ part of 'game_dao.dart'; // ignore_for_file: type=lint mixin _$GameDaoMixin on DatabaseAccessor { $GameTableTable get gameTable => attachedDatabase.gameTable; + GameDaoManager get managers => GameDaoManager(this); +} + +class GameDaoManager { + final _$GameDaoMixin _db; + GameDaoManager(this._db); + $$GameTableTableTableManager get gameTable => + $$GameTableTableTableManager(_db.attachedDatabase, _db.gameTable); } diff --git a/lib/data/dao/group_dao.dart b/lib/data/dao/group_dao.dart index 552b566..0d66ef6 100644 --- a/lib/data/dao/group_dao.dart +++ b/lib/data/dao/group_dao.dart @@ -3,8 +3,8 @@ import 'package:tallee/data/db/database.dart'; import 'package:tallee/data/db/tables/group_table.dart'; import 'package:tallee/data/db/tables/match_table.dart'; import 'package:tallee/data/db/tables/player_group_table.dart'; -import 'package:tallee/data/dto/group.dart'; -import 'package:tallee/data/dto/player.dart'; +import 'package:tallee/data/models/group.dart'; +import 'package:tallee/data/models/player.dart'; part 'group_dao.g.dart'; diff --git a/lib/data/dao/group_dao.g.dart b/lib/data/dao/group_dao.g.dart index 37a5586..665c93c 100644 --- a/lib/data/dao/group_dao.g.dart +++ b/lib/data/dao/group_dao.g.dart @@ -10,4 +10,23 @@ mixin _$GroupDaoMixin on DatabaseAccessor { attachedDatabase.playerGroupTable; $GameTableTable get gameTable => attachedDatabase.gameTable; $MatchTableTable get matchTable => attachedDatabase.matchTable; + GroupDaoManager get managers => GroupDaoManager(this); +} + +class GroupDaoManager { + final _$GroupDaoMixin _db; + GroupDaoManager(this._db); + $$GroupTableTableTableManager get groupTable => + $$GroupTableTableTableManager(_db.attachedDatabase, _db.groupTable); + $$PlayerTableTableTableManager get playerTable => + $$PlayerTableTableTableManager(_db.attachedDatabase, _db.playerTable); + $$PlayerGroupTableTableTableManager get playerGroupTable => + $$PlayerGroupTableTableTableManager( + _db.attachedDatabase, + _db.playerGroupTable, + ); + $$GameTableTableTableManager get gameTable => + $$GameTableTableTableManager(_db.attachedDatabase, _db.gameTable); + $$MatchTableTableTableManager get matchTable => + $$MatchTableTableTableManager(_db.attachedDatabase, _db.matchTable); } diff --git a/lib/data/dao/match_dao.dart b/lib/data/dao/match_dao.dart index d3fd06f..aed674c 100644 --- a/lib/data/dao/match_dao.dart +++ b/lib/data/dao/match_dao.dart @@ -4,10 +4,10 @@ import 'package:tallee/data/db/tables/game_table.dart'; import 'package:tallee/data/db/tables/group_table.dart'; import 'package:tallee/data/db/tables/match_table.dart'; import 'package:tallee/data/db/tables/player_match_table.dart'; -import 'package:tallee/data/dto/game.dart'; -import 'package:tallee/data/dto/group.dart'; -import 'package:tallee/data/dto/match.dart'; -import 'package:tallee/data/dto/player.dart'; +import 'package:tallee/data/models/game.dart'; +import 'package:tallee/data/models/group.dart'; +import 'package:tallee/data/models/match.dart'; +import 'package:tallee/data/models/player.dart'; part 'match_dao.g.dart'; diff --git a/lib/data/dao/match_dao.g.dart b/lib/data/dao/match_dao.g.dart index fa75fee..e3c7777 100644 --- a/lib/data/dao/match_dao.g.dart +++ b/lib/data/dao/match_dao.g.dart @@ -11,4 +11,25 @@ mixin _$MatchDaoMixin on DatabaseAccessor { $TeamTableTable get teamTable => attachedDatabase.teamTable; $PlayerMatchTableTable get playerMatchTable => attachedDatabase.playerMatchTable; + MatchDaoManager get managers => MatchDaoManager(this); +} + +class MatchDaoManager { + final _$MatchDaoMixin _db; + MatchDaoManager(this._db); + $$GameTableTableTableManager get gameTable => + $$GameTableTableTableManager(_db.attachedDatabase, _db.gameTable); + $$GroupTableTableTableManager get groupTable => + $$GroupTableTableTableManager(_db.attachedDatabase, _db.groupTable); + $$MatchTableTableTableManager get matchTable => + $$MatchTableTableTableManager(_db.attachedDatabase, _db.matchTable); + $$PlayerTableTableTableManager get playerTable => + $$PlayerTableTableTableManager(_db.attachedDatabase, _db.playerTable); + $$TeamTableTableTableManager get teamTable => + $$TeamTableTableTableManager(_db.attachedDatabase, _db.teamTable); + $$PlayerMatchTableTableTableManager get playerMatchTable => + $$PlayerMatchTableTableTableManager( + _db.attachedDatabase, + _db.playerMatchTable, + ); } diff --git a/lib/data/dao/player_dao.dart b/lib/data/dao/player_dao.dart index 2da9761..c58cb9a 100644 --- a/lib/data/dao/player_dao.dart +++ b/lib/data/dao/player_dao.dart @@ -1,7 +1,7 @@ import 'package:drift/drift.dart'; import 'package:tallee/data/db/database.dart'; import 'package:tallee/data/db/tables/player_table.dart'; -import 'package:tallee/data/dto/player.dart'; +import 'package:tallee/data/models/player.dart'; part 'player_dao.g.dart'; diff --git a/lib/data/dao/player_dao.g.dart b/lib/data/dao/player_dao.g.dart index c517581..9fefbf0 100644 --- a/lib/data/dao/player_dao.g.dart +++ b/lib/data/dao/player_dao.g.dart @@ -5,4 +5,12 @@ part of 'player_dao.dart'; // ignore_for_file: type=lint mixin _$PlayerDaoMixin on DatabaseAccessor { $PlayerTableTable get playerTable => attachedDatabase.playerTable; + PlayerDaoManager get managers => PlayerDaoManager(this); +} + +class PlayerDaoManager { + final _$PlayerDaoMixin _db; + PlayerDaoManager(this._db); + $$PlayerTableTableTableManager get playerTable => + $$PlayerTableTableTableManager(_db.attachedDatabase, _db.playerTable); } diff --git a/lib/data/dao/player_group_dao.dart b/lib/data/dao/player_group_dao.dart index c3889c8..9411486 100644 --- a/lib/data/dao/player_group_dao.dart +++ b/lib/data/dao/player_group_dao.dart @@ -2,7 +2,7 @@ import 'package:drift/drift.dart'; import 'package:tallee/data/db/database.dart'; import 'package:tallee/data/db/tables/player_group_table.dart'; import 'package:tallee/data/db/tables/player_table.dart'; -import 'package:tallee/data/dto/player.dart'; +import 'package:tallee/data/models/player.dart'; part 'player_group_dao.g.dart'; diff --git a/lib/data/dao/player_group_dao.g.dart b/lib/data/dao/player_group_dao.g.dart index d54f979..ef7e7e3 100644 --- a/lib/data/dao/player_group_dao.g.dart +++ b/lib/data/dao/player_group_dao.g.dart @@ -8,4 +8,19 @@ mixin _$PlayerGroupDaoMixin on DatabaseAccessor { $GroupTableTable get groupTable => attachedDatabase.groupTable; $PlayerGroupTableTable get playerGroupTable => attachedDatabase.playerGroupTable; + PlayerGroupDaoManager get managers => PlayerGroupDaoManager(this); +} + +class PlayerGroupDaoManager { + final _$PlayerGroupDaoMixin _db; + PlayerGroupDaoManager(this._db); + $$PlayerTableTableTableManager get playerTable => + $$PlayerTableTableTableManager(_db.attachedDatabase, _db.playerTable); + $$GroupTableTableTableManager get groupTable => + $$GroupTableTableTableManager(_db.attachedDatabase, _db.groupTable); + $$PlayerGroupTableTableTableManager get playerGroupTable => + $$PlayerGroupTableTableTableManager( + _db.attachedDatabase, + _db.playerGroupTable, + ); } diff --git a/lib/data/dao/player_match_dao.dart b/lib/data/dao/player_match_dao.dart index 48bf282..4ae40d1 100644 --- a/lib/data/dao/player_match_dao.dart +++ b/lib/data/dao/player_match_dao.dart @@ -2,7 +2,7 @@ import 'package:drift/drift.dart'; import 'package:tallee/data/db/database.dart'; import 'package:tallee/data/db/tables/player_match_table.dart'; import 'package:tallee/data/db/tables/team_table.dart'; -import 'package:tallee/data/dto/player.dart'; +import 'package:tallee/data/models/player.dart'; part 'player_match_dao.g.dart'; @@ -40,7 +40,7 @@ class PlayerMatchDao extends DatabaseAccessor if (result.isEmpty) return null; final futures = result.map( - (row) => db.playerDao.getPlayerById(playerId: row.playerId), + (row) => db.playerDao.getPlayerById(playerId: row.playerId), ); final players = await Future.wait(futures); return players; @@ -52,11 +52,11 @@ class PlayerMatchDao extends DatabaseAccessor required String matchId, required String playerId, }) async { - final result = await (select(playerMatchTable) - ..where( - (p) => p.matchId.equals(matchId) & p.playerId.equals(playerId), - )) - .getSingleOrNull(); + final result = + await (select(playerMatchTable)..where( + (p) => p.matchId.equals(matchId) & p.playerId.equals(playerId), + )) + .getSingleOrNull(); return result?.score; } @@ -67,11 +67,11 @@ class PlayerMatchDao extends DatabaseAccessor 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))); + final rowsAffected = + await (update(playerMatchTable)..where( + (p) => p.matchId.equals(matchId) & p.playerId.equals(playerId), + )) + .write(PlayerMatchTableCompanion(score: Value(newScore))); return rowsAffected > 0; } @@ -82,11 +82,11 @@ class PlayerMatchDao extends DatabaseAccessor required String playerId, required String? teamId, }) async { - final rowsAffected = await (update(playerMatchTable) - ..where( - (p) => p.matchId.equals(matchId) & p.playerId.equals(playerId), - )) - .write(PlayerMatchTableCompanion(teamId: Value(teamId))); + final rowsAffected = + await (update(playerMatchTable)..where( + (p) => p.matchId.equals(matchId) & p.playerId.equals(playerId), + )) + .write(PlayerMatchTableCompanion(teamId: Value(teamId))); return rowsAffected > 0; } @@ -94,11 +94,11 @@ class PlayerMatchDao extends DatabaseAccessor /// Returns `true` if there are players, otherwise `false`. Future matchHasPlayers({required String matchId}) async { final count = - await (selectOnly(playerMatchTable) - ..where(playerMatchTable.matchId.equals(matchId)) - ..addColumns([playerMatchTable.playerId.count()])) - .map((row) => row.read(playerMatchTable.playerId.count())) - .getSingle(); + await (selectOnly(playerMatchTable) + ..where(playerMatchTable.matchId.equals(matchId)) + ..addColumns([playerMatchTable.playerId.count()])) + .map((row) => row.read(playerMatchTable.playerId.count())) + .getSingle(); return (count ?? 0) > 0; } @@ -109,12 +109,12 @@ class PlayerMatchDao extends DatabaseAccessor required String playerId, }) async { final count = - await (selectOnly(playerMatchTable) - ..where(playerMatchTable.matchId.equals(matchId)) - ..where(playerMatchTable.playerId.equals(playerId)) - ..addColumns([playerMatchTable.playerId.count()])) - .map((row) => row.read(playerMatchTable.playerId.count())) - .getSingle(); + await (selectOnly(playerMatchTable) + ..where(playerMatchTable.matchId.equals(matchId)) + ..where(playerMatchTable.playerId.equals(playerId)) + ..addColumns([playerMatchTable.playerId.count()])) + .map((row) => row.read(playerMatchTable.playerId.count())) + .getSingle(); return (count ?? 0) > 0; } @@ -153,9 +153,9 @@ class PlayerMatchDao extends DatabaseAccessor if (playersToRemove.isNotEmpty) { await (delete(playerMatchTable)..where( (pg) => - pg.matchId.equals(matchId) & - pg.playerId.isIn(playersToRemove.toList()), - )) + pg.matchId.equals(matchId) & + pg.playerId.isIn(playersToRemove.toList()), + )) .go(); } @@ -164,15 +164,15 @@ class PlayerMatchDao extends DatabaseAccessor final inserts = playersToAdd .map( (id) => PlayerMatchTableCompanion.insert( - playerId: id, - matchId: matchId, - score: 0, - ), - ) + playerId: id, + matchId: matchId, + score: 0, + ), + ) .toList(); await Future.wait( inserts.map( - (c) => into( + (c) => into( playerMatchTable, ).insert(c, mode: InsertMode.insertOrIgnore), ), @@ -186,16 +186,14 @@ class PlayerMatchDao extends DatabaseAccessor required String matchId, required String teamId, }) async { - final result = await (select(playerMatchTable) - ..where( - (p) => p.matchId.equals(matchId) & p.teamId.equals(teamId), - )) - .get(); + final result = await (select( + playerMatchTable, + )..where((p) => p.matchId.equals(matchId) & p.teamId.equals(teamId))).get(); if (result.isEmpty) return []; final futures = result.map( - (row) => db.playerDao.getPlayerById(playerId: row.playerId), + (row) => db.playerDao.getPlayerById(playerId: row.playerId), ); return Future.wait(futures); } diff --git a/lib/data/dao/player_match_dao.g.dart b/lib/data/dao/player_match_dao.g.dart index 4c8bcbe..9ee099a 100644 --- a/lib/data/dao/player_match_dao.g.dart +++ b/lib/data/dao/player_match_dao.g.dart @@ -11,4 +11,25 @@ mixin _$PlayerMatchDaoMixin on DatabaseAccessor { $TeamTableTable get teamTable => attachedDatabase.teamTable; $PlayerMatchTableTable get playerMatchTable => attachedDatabase.playerMatchTable; + PlayerMatchDaoManager get managers => PlayerMatchDaoManager(this); +} + +class PlayerMatchDaoManager { + final _$PlayerMatchDaoMixin _db; + PlayerMatchDaoManager(this._db); + $$PlayerTableTableTableManager get playerTable => + $$PlayerTableTableTableManager(_db.attachedDatabase, _db.playerTable); + $$GameTableTableTableManager get gameTable => + $$GameTableTableTableManager(_db.attachedDatabase, _db.gameTable); + $$GroupTableTableTableManager get groupTable => + $$GroupTableTableTableManager(_db.attachedDatabase, _db.groupTable); + $$MatchTableTableTableManager get matchTable => + $$MatchTableTableTableManager(_db.attachedDatabase, _db.matchTable); + $$TeamTableTableTableManager get teamTable => + $$TeamTableTableTableManager(_db.attachedDatabase, _db.teamTable); + $$PlayerMatchTableTableTableManager get playerMatchTable => + $$PlayerMatchTableTableTableManager( + _db.attachedDatabase, + _db.playerMatchTable, + ); } diff --git a/lib/data/dao/score_dao.dart b/lib/data/dao/score_dao.dart index 111b2ae..11ec317 100644 --- a/lib/data/dao/score_dao.dart +++ b/lib/data/dao/score_dao.dart @@ -1,7 +1,7 @@ import 'package:drift/drift.dart'; import 'package:tallee/data/db/database.dart'; import 'package:tallee/data/db/tables/score_table.dart'; -import 'package:tallee/data/dto/score_entry.dart'; +import 'package:tallee/data/models/score_entry.dart'; part 'score_dao.g.dart'; diff --git a/lib/data/dao/score_dao.g.dart b/lib/data/dao/score_dao.g.dart index 1f4e367..046028c 100644 --- a/lib/data/dao/score_dao.g.dart +++ b/lib/data/dao/score_dao.g.dart @@ -9,4 +9,20 @@ mixin _$ScoreDaoMixin on DatabaseAccessor { $GroupTableTable get groupTable => attachedDatabase.groupTable; $MatchTableTable get matchTable => attachedDatabase.matchTable; $ScoreTableTable get scoreTable => attachedDatabase.scoreTable; + ScoreDaoManager get managers => ScoreDaoManager(this); +} + +class ScoreDaoManager { + final _$ScoreDaoMixin _db; + ScoreDaoManager(this._db); + $$PlayerTableTableTableManager get playerTable => + $$PlayerTableTableTableManager(_db.attachedDatabase, _db.playerTable); + $$GameTableTableTableManager get gameTable => + $$GameTableTableTableManager(_db.attachedDatabase, _db.gameTable); + $$GroupTableTableTableManager get groupTable => + $$GroupTableTableTableManager(_db.attachedDatabase, _db.groupTable); + $$MatchTableTableTableManager get matchTable => + $$MatchTableTableTableManager(_db.attachedDatabase, _db.matchTable); + $$ScoreTableTableTableManager get scoreTable => + $$ScoreTableTableTableManager(_db.attachedDatabase, _db.scoreTable); } diff --git a/lib/data/dao/team_dao.dart b/lib/data/dao/team_dao.dart index 5c2aadb..01dc724 100644 --- a/lib/data/dao/team_dao.dart +++ b/lib/data/dao/team_dao.dart @@ -1,8 +1,8 @@ import 'package:drift/drift.dart'; import 'package:tallee/data/db/database.dart'; import 'package:tallee/data/db/tables/team_table.dart'; -import 'package:tallee/data/dto/player.dart'; -import 'package:tallee/data/dto/team.dart'; +import 'package:tallee/data/models/player.dart'; +import 'package:tallee/data/models/team.dart'; part 'team_dao.g.dart'; @@ -144,4 +144,3 @@ class TeamDao extends DatabaseAccessor with _$TeamDaoMixin { return rowsAffected > 0; } } - diff --git a/lib/data/dao/team_dao.g.dart b/lib/data/dao/team_dao.g.dart index 1bf5b21..3b78c03 100644 --- a/lib/data/dao/team_dao.g.dart +++ b/lib/data/dao/team_dao.g.dart @@ -5,4 +5,12 @@ part of 'team_dao.dart'; // ignore_for_file: type=lint mixin _$TeamDaoMixin on DatabaseAccessor { $TeamTableTable get teamTable => attachedDatabase.teamTable; + TeamDaoManager get managers => TeamDaoManager(this); +} + +class TeamDaoManager { + final _$TeamDaoMixin _db; + TeamDaoManager(this._db); + $$TeamTableTableTableManager get teamTable => + $$TeamTableTableTableManager(_db.attachedDatabase, _db.teamTable); } diff --git a/lib/data/db/database.g.dart b/lib/data/db/database.g.dart index 227c7c0..81b28a5 100644 --- a/lib/data/db/database.g.dart +++ b/lib/data/db/database.g.dart @@ -1131,9 +1131,9 @@ class $MatchTableTable extends MatchTable late final GeneratedColumn name = GeneratedColumn( 'name', aliasedName, - true, + false, type: DriftSqlType.string, - requiredDuringInsert: false, + requiredDuringInsert: true, ); static const VerificationMeta _notesMeta = const VerificationMeta('notes'); @override @@ -1212,6 +1212,8 @@ class $MatchTableTable extends MatchTable _nameMeta, name.isAcceptableOrUnknown(data['name']!, _nameMeta), ); + } else if (isInserting) { + context.missing(_nameMeta); } if (data.containsKey('notes')) { context.handle( @@ -1257,7 +1259,7 @@ class $MatchTableTable extends MatchTable name: attachedDatabase.typeMapping.read( DriftSqlType.string, data['${effectivePrefix}name'], - ), + )!, notes: attachedDatabase.typeMapping.read( DriftSqlType.string, data['${effectivePrefix}notes'], @@ -1283,7 +1285,7 @@ class MatchTableData extends DataClass implements Insertable { final String id; final String gameId; final String? groupId; - final String? name; + final String name; final String? notes; final DateTime createdAt; final DateTime? endedAt; @@ -1291,7 +1293,7 @@ class MatchTableData extends DataClass implements Insertable { required this.id, required this.gameId, this.groupId, - this.name, + required this.name, this.notes, required this.createdAt, this.endedAt, @@ -1304,9 +1306,7 @@ class MatchTableData extends DataClass implements Insertable { if (!nullToAbsent || groupId != null) { map['group_id'] = Variable(groupId); } - if (!nullToAbsent || name != null) { - map['name'] = Variable(name); - } + map['name'] = Variable(name); if (!nullToAbsent || notes != null) { map['notes'] = Variable(notes); } @@ -1324,7 +1324,7 @@ class MatchTableData extends DataClass implements Insertable { groupId: groupId == null && nullToAbsent ? const Value.absent() : Value(groupId), - name: name == null && nullToAbsent ? const Value.absent() : Value(name), + name: Value(name), notes: notes == null && nullToAbsent ? const Value.absent() : Value(notes), @@ -1344,7 +1344,7 @@ class MatchTableData extends DataClass implements Insertable { id: serializer.fromJson(json['id']), gameId: serializer.fromJson(json['gameId']), groupId: serializer.fromJson(json['groupId']), - name: serializer.fromJson(json['name']), + name: serializer.fromJson(json['name']), notes: serializer.fromJson(json['notes']), createdAt: serializer.fromJson(json['createdAt']), endedAt: serializer.fromJson(json['endedAt']), @@ -1357,7 +1357,7 @@ class MatchTableData extends DataClass implements Insertable { 'id': serializer.toJson(id), 'gameId': serializer.toJson(gameId), 'groupId': serializer.toJson(groupId), - 'name': serializer.toJson(name), + 'name': serializer.toJson(name), 'notes': serializer.toJson(notes), 'createdAt': serializer.toJson(createdAt), 'endedAt': serializer.toJson(endedAt), @@ -1368,7 +1368,7 @@ class MatchTableData extends DataClass implements Insertable { String? id, String? gameId, Value groupId = const Value.absent(), - Value name = const Value.absent(), + String? name, Value notes = const Value.absent(), DateTime? createdAt, Value endedAt = const Value.absent(), @@ -1376,7 +1376,7 @@ class MatchTableData extends DataClass implements Insertable { id: id ?? this.id, gameId: gameId ?? this.gameId, groupId: groupId.present ? groupId.value : this.groupId, - name: name.present ? name.value : this.name, + name: name ?? this.name, notes: notes.present ? notes.value : this.notes, createdAt: createdAt ?? this.createdAt, endedAt: endedAt.present ? endedAt.value : this.endedAt, @@ -1427,7 +1427,7 @@ class MatchTableCompanion extends UpdateCompanion { final Value id; final Value gameId; final Value groupId; - final Value name; + final Value name; final Value notes; final Value createdAt; final Value endedAt; @@ -1446,13 +1446,14 @@ class MatchTableCompanion extends UpdateCompanion { required String id, required String gameId, this.groupId = const Value.absent(), - this.name = const Value.absent(), + required String name, this.notes = const Value.absent(), required DateTime createdAt, this.endedAt = const Value.absent(), this.rowid = const Value.absent(), }) : id = Value(id), gameId = Value(gameId), + name = Value(name), createdAt = Value(createdAt); static Insertable custom({ Expression? id, @@ -1480,7 +1481,7 @@ class MatchTableCompanion extends UpdateCompanion { Value? id, Value? gameId, Value? groupId, - Value? name, + Value? name, Value? notes, Value? createdAt, Value? endedAt, @@ -2074,17 +2075,8 @@ class $PlayerMatchTableTable extends PlayerMatchTable 'REFERENCES team_table (id)', ), ); - static const VerificationMeta _scoreMeta = const VerificationMeta('score'); @override - late final GeneratedColumn score = GeneratedColumn( - 'score', - aliasedName, - false, - type: DriftSqlType.int, - requiredDuringInsert: true, - ); - @override - List get $columns => [playerId, matchId, teamId, score]; + List get $columns => [playerId, matchId, teamId]; @override String get aliasedName => _alias ?? actualTableName; @override @@ -2119,14 +2111,6 @@ class $PlayerMatchTableTable extends PlayerMatchTable teamId.isAcceptableOrUnknown(data['team_id']!, _teamIdMeta), ); } - if (data.containsKey('score')) { - context.handle( - _scoreMeta, - score.isAcceptableOrUnknown(data['score']!, _scoreMeta), - ); - } else if (isInserting) { - context.missing(_scoreMeta); - } return context; } @@ -2148,10 +2132,6 @@ class $PlayerMatchTableTable extends PlayerMatchTable DriftSqlType.string, data['${effectivePrefix}team_id'], ), - score: attachedDatabase.typeMapping.read( - DriftSqlType.int, - data['${effectivePrefix}score'], - )!, ); } @@ -2166,12 +2146,10 @@ class PlayerMatchTableData extends DataClass final String playerId; final String matchId; final String? teamId; - final int score; const PlayerMatchTableData({ required this.playerId, required this.matchId, this.teamId, - required this.score, }); @override Map toColumns(bool nullToAbsent) { @@ -2181,7 +2159,6 @@ class PlayerMatchTableData extends DataClass if (!nullToAbsent || teamId != null) { map['team_id'] = Variable(teamId); } - map['score'] = Variable(score); return map; } @@ -2192,7 +2169,6 @@ class PlayerMatchTableData extends DataClass teamId: teamId == null && nullToAbsent ? const Value.absent() : Value(teamId), - score: Value(score), ); } @@ -2205,7 +2181,6 @@ class PlayerMatchTableData extends DataClass playerId: serializer.fromJson(json['playerId']), matchId: serializer.fromJson(json['matchId']), teamId: serializer.fromJson(json['teamId']), - score: serializer.fromJson(json['score']), ); } @override @@ -2215,7 +2190,6 @@ class PlayerMatchTableData extends DataClass 'playerId': serializer.toJson(playerId), 'matchId': serializer.toJson(matchId), 'teamId': serializer.toJson(teamId), - 'score': serializer.toJson(score), }; } @@ -2223,19 +2197,16 @@ class PlayerMatchTableData extends DataClass String? playerId, String? matchId, Value teamId = const Value.absent(), - int? score, }) => PlayerMatchTableData( playerId: playerId ?? this.playerId, matchId: matchId ?? this.matchId, teamId: teamId.present ? teamId.value : this.teamId, - score: score ?? this.score, ); PlayerMatchTableData copyWithCompanion(PlayerMatchTableCompanion data) { return PlayerMatchTableData( playerId: data.playerId.present ? data.playerId.value : this.playerId, matchId: data.matchId.present ? data.matchId.value : this.matchId, teamId: data.teamId.present ? data.teamId.value : this.teamId, - score: data.score.present ? data.score.value : this.score, ); } @@ -2244,58 +2215,50 @@ class PlayerMatchTableData extends DataClass return (StringBuffer('PlayerMatchTableData(') ..write('playerId: $playerId, ') ..write('matchId: $matchId, ') - ..write('teamId: $teamId, ') - ..write('score: $score') + ..write('teamId: $teamId') ..write(')')) .toString(); } @override - int get hashCode => Object.hash(playerId, matchId, teamId, score); + int get hashCode => Object.hash(playerId, matchId, teamId); @override bool operator ==(Object other) => identical(this, other) || (other is PlayerMatchTableData && other.playerId == this.playerId && other.matchId == this.matchId && - other.teamId == this.teamId && - other.score == this.score); + other.teamId == this.teamId); } class PlayerMatchTableCompanion extends UpdateCompanion { final Value playerId; final Value matchId; final Value teamId; - final Value score; final Value rowid; const PlayerMatchTableCompanion({ this.playerId = const Value.absent(), this.matchId = const Value.absent(), this.teamId = const Value.absent(), - this.score = const Value.absent(), this.rowid = const Value.absent(), }); PlayerMatchTableCompanion.insert({ required String playerId, required String matchId, this.teamId = const Value.absent(), - required int score, this.rowid = const Value.absent(), }) : playerId = Value(playerId), - matchId = Value(matchId), - score = Value(score); + matchId = Value(matchId); static Insertable custom({ Expression? playerId, Expression? matchId, Expression? teamId, - Expression? score, Expression? rowid, }) { return RawValuesInsertable({ if (playerId != null) 'player_id': playerId, if (matchId != null) 'match_id': matchId, if (teamId != null) 'team_id': teamId, - if (score != null) 'score': score, if (rowid != null) 'rowid': rowid, }); } @@ -2304,14 +2267,12 @@ class PlayerMatchTableCompanion extends UpdateCompanion { Value? playerId, Value? matchId, Value? teamId, - Value? score, Value? rowid, }) { return PlayerMatchTableCompanion( playerId: playerId ?? this.playerId, matchId: matchId ?? this.matchId, teamId: teamId ?? this.teamId, - score: score ?? this.score, rowid: rowid ?? this.rowid, ); } @@ -2328,9 +2289,6 @@ class PlayerMatchTableCompanion extends UpdateCompanion { if (teamId.present) { map['team_id'] = Variable(teamId.value); } - if (score.present) { - map['score'] = Variable(score.value); - } if (rowid.present) { map['rowid'] = Variable(rowid.value); } @@ -2343,7 +2301,6 @@ class PlayerMatchTableCompanion extends UpdateCompanion { ..write('playerId: $playerId, ') ..write('matchId: $matchId, ') ..write('teamId: $teamId, ') - ..write('score: $score, ') ..write('rowid: $rowid') ..write(')')) .toString(); @@ -4051,7 +4008,7 @@ typedef $$MatchTableTableCreateCompanionBuilder = required String id, required String gameId, Value groupId, - Value name, + required String name, Value notes, required DateTime createdAt, Value endedAt, @@ -4062,7 +4019,7 @@ typedef $$MatchTableTableUpdateCompanionBuilder = Value id, Value gameId, Value groupId, - Value name, + Value name, Value notes, Value createdAt, Value endedAt, @@ -4520,7 +4477,7 @@ class $$MatchTableTableTableManager Value id = const Value.absent(), Value gameId = const Value.absent(), Value groupId = const Value.absent(), - Value name = const Value.absent(), + Value name = const Value.absent(), Value notes = const Value.absent(), Value createdAt = const Value.absent(), Value endedAt = const Value.absent(), @@ -4540,7 +4497,7 @@ class $$MatchTableTableTableManager required String id, required String gameId, Value groupId = const Value.absent(), - Value name = const Value.absent(), + required String name, Value notes = const Value.absent(), required DateTime createdAt, Value endedAt = const Value.absent(), @@ -5334,7 +5291,6 @@ typedef $$PlayerMatchTableTableCreateCompanionBuilder = required String playerId, required String matchId, Value teamId, - required int score, Value rowid, }); typedef $$PlayerMatchTableTableUpdateCompanionBuilder = @@ -5342,7 +5298,6 @@ typedef $$PlayerMatchTableTableUpdateCompanionBuilder = Value playerId, Value matchId, Value teamId, - Value score, Value rowid, }); @@ -5426,11 +5381,6 @@ class $$PlayerMatchTableTableFilterComposer super.$addJoinBuilderToRootComposer, super.$removeJoinBuilderFromRootComposer, }); - ColumnFilters get score => $composableBuilder( - column: $table.score, - builder: (column) => ColumnFilters(column), - ); - $$PlayerTableTableFilterComposer get playerId { final $$PlayerTableTableFilterComposer composer = $composerBuilder( composer: this, @@ -5510,11 +5460,6 @@ class $$PlayerMatchTableTableOrderingComposer super.$addJoinBuilderToRootComposer, super.$removeJoinBuilderFromRootComposer, }); - ColumnOrderings get score => $composableBuilder( - column: $table.score, - builder: (column) => ColumnOrderings(column), - ); - $$PlayerTableTableOrderingComposer get playerId { final $$PlayerTableTableOrderingComposer composer = $composerBuilder( composer: this, @@ -5594,9 +5539,6 @@ class $$PlayerMatchTableTableAnnotationComposer super.$addJoinBuilderToRootComposer, super.$removeJoinBuilderFromRootComposer, }); - GeneratedColumn get score => - $composableBuilder(column: $table.score, builder: (column) => column); - $$PlayerTableTableAnnotationComposer get playerId { final $$PlayerTableTableAnnotationComposer composer = $composerBuilder( composer: this, @@ -5700,13 +5642,11 @@ class $$PlayerMatchTableTableTableManager Value playerId = const Value.absent(), Value matchId = const Value.absent(), Value teamId = const Value.absent(), - Value score = const Value.absent(), Value rowid = const Value.absent(), }) => PlayerMatchTableCompanion( playerId: playerId, matchId: matchId, teamId: teamId, - score: score, rowid: rowid, ), createCompanionCallback: @@ -5714,13 +5654,11 @@ class $$PlayerMatchTableTableTableManager required String playerId, required String matchId, Value teamId = const Value.absent(), - required int score, Value rowid = const Value.absent(), }) => PlayerMatchTableCompanion.insert( playerId: playerId, matchId: matchId, teamId: teamId, - score: score, rowid: rowid, ), withReferenceMapper: (p0) => p0 diff --git a/lib/data/dto/game.dart b/lib/data/models/game.dart similarity index 100% rename from lib/data/dto/game.dart rename to lib/data/models/game.dart diff --git a/lib/data/dto/group.dart b/lib/data/models/group.dart similarity index 96% rename from lib/data/dto/group.dart rename to lib/data/models/group.dart index 7676b1e..aa3961c 100644 --- a/lib/data/dto/group.dart +++ b/lib/data/models/group.dart @@ -1,5 +1,5 @@ import 'package:clock/clock.dart'; -import 'package:tallee/data/dto/player.dart'; +import 'package:tallee/data/models/player.dart'; import 'package:uuid/uuid.dart'; class Group { diff --git a/lib/data/dto/match.dart b/lib/data/models/match.dart similarity index 91% rename from lib/data/dto/match.dart rename to lib/data/models/match.dart index 69b7c9c..6d2d033 100644 --- a/lib/data/dto/match.dart +++ b/lib/data/models/match.dart @@ -1,9 +1,9 @@ import 'package:clock/clock.dart'; import 'package:tallee/core/enums.dart'; -import 'package:tallee/data/dto/game.dart'; -import 'package:tallee/data/dto/group.dart'; -import 'package:tallee/data/dto/player.dart'; -import 'package:tallee/data/dto/score_entry.dart'; +import 'package:tallee/data/models/game.dart'; +import 'package:tallee/data/models/group.dart'; +import 'package:tallee/data/models/player.dart'; +import 'package:tallee/data/models/score_entry.dart'; import 'package:uuid/uuid.dart'; class Match { diff --git a/lib/data/dto/player.dart b/lib/data/models/player.dart similarity index 100% rename from lib/data/dto/player.dart rename to lib/data/models/player.dart diff --git a/lib/data/dto/score_entry.dart b/lib/data/models/score_entry.dart similarity index 100% rename from lib/data/dto/score_entry.dart rename to lib/data/models/score_entry.dart diff --git a/lib/data/dto/team.dart b/lib/data/models/team.dart similarity index 95% rename from lib/data/dto/team.dart rename to lib/data/models/team.dart index 56036b2..8c16280 100644 --- a/lib/data/dto/team.dart +++ b/lib/data/models/team.dart @@ -1,5 +1,5 @@ import 'package:clock/clock.dart'; -import 'package:tallee/data/dto/player.dart'; +import 'package:tallee/data/models/player.dart'; import 'package:uuid/uuid.dart'; class Team { @@ -37,4 +37,3 @@ class Team { 'memberIds': members.map((member) => member.id).toList(), }; } - diff --git a/lib/presentation/views/main_menu/group_view/create_group_view.dart b/lib/presentation/views/main_menu/group_view/create_group_view.dart index 8829343..d5ac6a4 100644 --- a/lib/presentation/views/main_menu/group_view/create_group_view.dart +++ b/lib/presentation/views/main_menu/group_view/create_group_view.dart @@ -4,8 +4,8 @@ import 'package:tallee/core/constants.dart'; import 'package:tallee/core/custom_theme.dart'; import 'package:tallee/core/enums.dart'; import 'package:tallee/data/db/database.dart'; -import 'package:tallee/data/dto/group.dart'; -import 'package:tallee/data/dto/player.dart'; +import 'package:tallee/data/models/group.dart'; +import 'package:tallee/data/models/player.dart'; import 'package:tallee/l10n/generated/app_localizations.dart'; import 'package:tallee/presentation/widgets/buttons/custom_width_button.dart'; import 'package:tallee/presentation/widgets/player_selection.dart'; diff --git a/lib/presentation/views/main_menu/group_view/group_detail_view.dart b/lib/presentation/views/main_menu/group_view/group_detail_view.dart index c9ffa25..1ef89ef 100644 --- a/lib/presentation/views/main_menu/group_view/group_detail_view.dart +++ b/lib/presentation/views/main_menu/group_view/group_detail_view.dart @@ -4,9 +4,9 @@ import 'package:provider/provider.dart'; import 'package:tallee/core/adaptive_page_route.dart'; import 'package:tallee/core/custom_theme.dart'; import 'package:tallee/data/db/database.dart'; -import 'package:tallee/data/dto/group.dart'; -import 'package:tallee/data/dto/match.dart'; -import 'package:tallee/data/dto/player.dart'; +import 'package:tallee/data/models/group.dart'; +import 'package:tallee/data/models/match.dart'; +import 'package:tallee/data/models/player.dart'; import 'package:tallee/l10n/generated/app_localizations.dart'; import 'package:tallee/presentation/views/main_menu/group_view/create_group_view.dart'; import 'package:tallee/presentation/widgets/app_skeleton.dart'; diff --git a/lib/presentation/views/main_menu/group_view/group_view.dart b/lib/presentation/views/main_menu/group_view/group_view.dart index 90b682a..b091541 100644 --- a/lib/presentation/views/main_menu/group_view/group_view.dart +++ b/lib/presentation/views/main_menu/group_view/group_view.dart @@ -4,8 +4,8 @@ import 'package:tallee/core/adaptive_page_route.dart'; import 'package:tallee/core/constants.dart'; import 'package:tallee/core/custom_theme.dart'; import 'package:tallee/data/db/database.dart'; -import 'package:tallee/data/dto/group.dart'; -import 'package:tallee/data/dto/player.dart'; +import 'package:tallee/data/models/group.dart'; +import 'package:tallee/data/models/player.dart'; import 'package:tallee/l10n/generated/app_localizations.dart'; import 'package:tallee/presentation/views/main_menu/group_view/create_group_view.dart'; import 'package:tallee/presentation/views/main_menu/group_view/group_detail_view.dart'; diff --git a/lib/presentation/views/main_menu/home_view.dart b/lib/presentation/views/main_menu/home_view.dart index a7f5cfa..1dfbee2 100644 --- a/lib/presentation/views/main_menu/home_view.dart +++ b/lib/presentation/views/main_menu/home_view.dart @@ -4,10 +4,10 @@ import 'package:tallee/core/adaptive_page_route.dart'; import 'package:tallee/core/constants.dart'; import 'package:tallee/core/enums.dart'; import 'package:tallee/data/db/database.dart'; -import 'package:tallee/data/dto/game.dart'; -import 'package:tallee/data/dto/group.dart'; -import 'package:tallee/data/dto/match.dart'; -import 'package:tallee/data/dto/player.dart'; +import 'package:tallee/data/models/game.dart'; +import 'package:tallee/data/models/group.dart'; +import 'package:tallee/data/models/match.dart'; +import 'package:tallee/data/models/player.dart'; import 'package:tallee/l10n/generated/app_localizations.dart'; import 'package:tallee/presentation/views/main_menu/match_view/match_result_view.dart'; import 'package:tallee/presentation/widgets/app_skeleton.dart'; @@ -42,7 +42,13 @@ class _HomeViewState extends State { 2, Match( name: 'Skeleton Match', - game: Game(name: '', ruleset: Ruleset.singleWinner, description: '', color: GameColor.blue, icon: ''), + game: Game( + name: '', + ruleset: Ruleset.singleWinner, + description: '', + color: GameColor.blue, + icon: '', + ), group: Group( name: 'Skeleton Group', description: '', @@ -104,7 +110,9 @@ class _HomeViewState extends State { if (recentMatches.isNotEmpty) for (Match match in recentMatches) Padding( - padding: const EdgeInsets.symmetric(vertical: 6.0), + padding: const EdgeInsets.symmetric( + vertical: 6.0, + ), child: MatchTile( compact: true, width: constraints.maxWidth * 0.9, @@ -113,7 +121,8 @@ class _HomeViewState extends State { await Navigator.of(context).push( adaptivePageRoute( fullscreenDialog: true, - builder: (context) => MatchResultView(match: match), + builder: (context) => + MatchResultView(match: match), ), ); await updatedWinnerInRecentMatches(match.id); @@ -121,7 +130,10 @@ class _HomeViewState extends State { ), ) else - Center(heightFactor: 5, child: Text(loc.no_recent_matches_available)), + Center( + heightFactor: 5, + child: Text(loc.no_recent_matches_available), + ), ], ), ), @@ -137,22 +149,40 @@ class _HomeViewState extends State { Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - QuickCreateButton(text: 'Category 1', onPressed: () {}), - QuickCreateButton(text: 'Category 2', onPressed: () {}), + QuickCreateButton( + text: 'Category 1', + onPressed: () {}, + ), + QuickCreateButton( + text: 'Category 2', + onPressed: () {}, + ), ], ), Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - QuickCreateButton(text: 'Category 3', onPressed: () {}), - QuickCreateButton(text: 'Category 4', onPressed: () {}), + QuickCreateButton( + text: 'Category 3', + onPressed: () {}, + ), + QuickCreateButton( + text: 'Category 4', + onPressed: () {}, + ), ], ), Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - QuickCreateButton(text: 'Category 5', onPressed: () {}), - QuickCreateButton(text: 'Category 6', onPressed: () {}), + QuickCreateButton( + text: 'Category 5', + onPressed: () {}, + ), + QuickCreateButton( + text: 'Category 6', + onPressed: () {}, + ), ], ), ], @@ -181,9 +211,11 @@ class _HomeViewState extends State { matchCount = results[0] as int; groupCount = results[1] as int; loadedRecentMatches = results[2] as List; - recentMatches = (loadedRecentMatches..sort((a, b) => b.createdAt.compareTo(a.createdAt))) - .take(2) - .toList(); + recentMatches = + (loadedRecentMatches + ..sort((a, b) => b.createdAt.compareTo(a.createdAt))) + .take(2) + .toList(); if (mounted) { setState(() { isLoading = false; diff --git a/lib/presentation/views/main_menu/match_view/create_match/choose_group_view.dart b/lib/presentation/views/main_menu/match_view/create_match/choose_group_view.dart index 9c60b16..c7471d8 100644 --- a/lib/presentation/views/main_menu/match_view/create_match/choose_group_view.dart +++ b/lib/presentation/views/main_menu/match_view/create_match/choose_group_view.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:tallee/core/custom_theme.dart'; -import 'package:tallee/data/dto/group.dart'; +import 'package:tallee/data/models/group.dart'; import 'package:tallee/l10n/generated/app_localizations.dart'; import 'package:tallee/presentation/widgets/text_input/custom_search_bar.dart'; import 'package:tallee/presentation/widgets/tiles/group_tile.dart'; diff --git a/lib/presentation/views/main_menu/match_view/create_match/create_match_view.dart b/lib/presentation/views/main_menu/match_view/create_match/create_match_view.dart index 8138957..950b3a8 100644 --- a/lib/presentation/views/main_menu/match_view/create_match/create_match_view.dart +++ b/lib/presentation/views/main_menu/match_view/create_match/create_match_view.dart @@ -5,10 +5,10 @@ import 'package:tallee/core/constants.dart'; import 'package:tallee/core/custom_theme.dart'; import 'package:tallee/core/enums.dart'; import 'package:tallee/data/db/database.dart'; -import 'package:tallee/data/dto/game.dart'; -import 'package:tallee/data/dto/group.dart'; -import 'package:tallee/data/dto/match.dart'; -import 'package:tallee/data/dto/player.dart'; +import 'package:tallee/data/models/game.dart'; +import 'package:tallee/data/models/group.dart'; +import 'package:tallee/data/models/match.dart'; +import 'package:tallee/data/models/player.dart'; import 'package:tallee/l10n/generated/app_localizations.dart'; import 'package:tallee/presentation/views/main_menu/match_view/create_match/choose_game_view.dart'; import 'package:tallee/presentation/views/main_menu/match_view/create_match/choose_group_view.dart'; diff --git a/lib/presentation/views/main_menu/match_view/match_detail_view.dart b/lib/presentation/views/main_menu/match_view/match_detail_view.dart index 1deba18..fc53aa8 100644 --- a/lib/presentation/views/main_menu/match_view/match_detail_view.dart +++ b/lib/presentation/views/main_menu/match_view/match_detail_view.dart @@ -5,7 +5,7 @@ import 'package:tallee/core/adaptive_page_route.dart'; import 'package:tallee/core/common.dart'; import 'package:tallee/core/custom_theme.dart'; import 'package:tallee/data/db/database.dart'; -import 'package:tallee/data/dto/match.dart'; +import 'package:tallee/data/models/match.dart'; import 'package:tallee/l10n/generated/app_localizations.dart'; import 'package:tallee/presentation/views/main_menu/match_view/create_match/create_match_view.dart'; import 'package:tallee/presentation/views/main_menu/match_view/match_result_view.dart'; diff --git a/lib/presentation/views/main_menu/match_view/match_result_view.dart b/lib/presentation/views/main_menu/match_view/match_result_view.dart index 8a46f13..5ac5482 100644 --- a/lib/presentation/views/main_menu/match_view/match_result_view.dart +++ b/lib/presentation/views/main_menu/match_view/match_result_view.dart @@ -2,8 +2,8 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:tallee/core/custom_theme.dart'; import 'package:tallee/data/db/database.dart'; -import 'package:tallee/data/dto/match.dart'; -import 'package:tallee/data/dto/player.dart'; +import 'package:tallee/data/models/match.dart'; +import 'package:tallee/data/models/player.dart'; import 'package:tallee/l10n/generated/app_localizations.dart'; import 'package:tallee/presentation/widgets/tiles/custom_radio_list_tile.dart'; diff --git a/lib/presentation/views/main_menu/match_view/match_view.dart b/lib/presentation/views/main_menu/match_view/match_view.dart index a090b46..1a202c4 100644 --- a/lib/presentation/views/main_menu/match_view/match_view.dart +++ b/lib/presentation/views/main_menu/match_view/match_view.dart @@ -6,10 +6,10 @@ import 'package:tallee/core/constants.dart'; import 'package:tallee/core/custom_theme.dart'; import 'package:tallee/core/enums.dart'; import 'package:tallee/data/db/database.dart'; -import 'package:tallee/data/dto/game.dart'; -import 'package:tallee/data/dto/group.dart'; -import 'package:tallee/data/dto/match.dart'; -import 'package:tallee/data/dto/player.dart'; +import 'package:tallee/data/models/game.dart'; +import 'package:tallee/data/models/group.dart'; +import 'package:tallee/data/models/match.dart'; +import 'package:tallee/data/models/player.dart'; import 'package:tallee/l10n/generated/app_localizations.dart'; import 'package:tallee/presentation/views/main_menu/match_view/create_match/create_match_view.dart'; import 'package:tallee/presentation/views/main_menu/match_view/match_detail_view.dart'; diff --git a/lib/presentation/views/main_menu/statistics_view.dart b/lib/presentation/views/main_menu/statistics_view.dart index 5b3ff22..3a55115 100644 --- a/lib/presentation/views/main_menu/statistics_view.dart +++ b/lib/presentation/views/main_menu/statistics_view.dart @@ -2,8 +2,8 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:tallee/core/constants.dart'; import 'package:tallee/data/db/database.dart'; -import 'package:tallee/data/dto/match.dart'; -import 'package:tallee/data/dto/player.dart'; +import 'package:tallee/data/models/match.dart'; +import 'package:tallee/data/models/player.dart'; import 'package:tallee/l10n/generated/app_localizations.dart'; import 'package:tallee/presentation/widgets/app_skeleton.dart'; import 'package:tallee/presentation/widgets/tiles/statistics_tile.dart'; @@ -167,7 +167,8 @@ class _StatisticsViewState extends State { final playerId = winCounts[i].$1; final player = players.firstWhere( (p) => p.id == playerId, - orElse: () => Player(id: playerId, name: loc.not_available, description: ''), + orElse: () => + Player(id: playerId, name: loc.not_available, description: ''), ); winCounts[i] = (player.name, winCounts[i].$2); } @@ -208,11 +209,11 @@ class _StatisticsViewState extends State { // -1 means player not found in matchCounts if (index != -1) { final current = matchCounts[index].$2; - matchCounts[index] = (playerId, current + 1); - } else { - matchCounts.add((playerId, 1)); - } + matchCounts[index] = (playerId, current + 1); + } else { + matchCounts.add((playerId, 1)); } + } } // Adding all players with zero matches @@ -229,7 +230,8 @@ class _StatisticsViewState extends State { final playerId = matchCounts[i].$1; final player = players.firstWhere( (p) => p.id == playerId, - orElse: () => Player(id: playerId, name: loc.not_available, description: ''), + orElse: () => + Player(id: playerId, name: loc.not_available, description: ''), ); matchCounts[i] = (player.name, matchCounts[i].$2); } diff --git a/lib/presentation/widgets/player_selection.dart b/lib/presentation/widgets/player_selection.dart index b51cadc..6d8769d 100644 --- a/lib/presentation/widgets/player_selection.dart +++ b/lib/presentation/widgets/player_selection.dart @@ -3,7 +3,7 @@ import 'package:provider/provider.dart'; import 'package:tallee/core/constants.dart'; import 'package:tallee/core/custom_theme.dart'; import 'package:tallee/data/db/database.dart'; -import 'package:tallee/data/dto/player.dart'; +import 'package:tallee/data/models/player.dart'; import 'package:tallee/l10n/generated/app_localizations.dart'; import 'package:tallee/presentation/widgets/app_skeleton.dart'; import 'package:tallee/presentation/widgets/text_input/custom_search_bar.dart'; diff --git a/lib/presentation/widgets/tiles/group_tile.dart b/lib/presentation/widgets/tiles/group_tile.dart index d662918..b62f3ce 100644 --- a/lib/presentation/widgets/tiles/group_tile.dart +++ b/lib/presentation/widgets/tiles/group_tile.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:tallee/core/custom_theme.dart'; -import 'package:tallee/data/dto/group.dart'; +import 'package:tallee/data/models/group.dart'; import 'package:tallee/presentation/widgets/tiles/text_icon_tile.dart'; class GroupTile extends StatefulWidget { diff --git a/lib/presentation/widgets/tiles/match_tile.dart b/lib/presentation/widgets/tiles/match_tile.dart index 3c36587..39f9cdf 100644 --- a/lib/presentation/widgets/tiles/match_tile.dart +++ b/lib/presentation/widgets/tiles/match_tile.dart @@ -4,7 +4,7 @@ import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; import 'package:tallee/core/common.dart'; import 'package:tallee/core/custom_theme.dart'; -import 'package:tallee/data/dto/match.dart'; +import 'package:tallee/data/models/match.dart'; import 'package:tallee/l10n/generated/app_localizations.dart'; import 'package:tallee/presentation/widgets/tiles/text_icon_tile.dart'; diff --git a/lib/services/data_transfer_service.dart b/lib/services/data_transfer_service.dart index 526a459..8ceee94 100644 --- a/lib/services/data_transfer_service.dart +++ b/lib/services/data_transfer_service.dart @@ -8,11 +8,11 @@ import 'package:json_schema/json_schema.dart'; import 'package:provider/provider.dart'; import 'package:tallee/core/enums.dart'; import 'package:tallee/data/db/database.dart'; -import 'package:tallee/data/dto/game.dart'; -import 'package:tallee/data/dto/group.dart'; -import 'package:tallee/data/dto/match.dart'; -import 'package:tallee/data/dto/player.dart'; -import 'package:tallee/data/dto/team.dart'; +import 'package:tallee/data/models/game.dart'; +import 'package:tallee/data/models/group.dart'; +import 'package:tallee/data/models/match.dart'; +import 'package:tallee/data/models/player.dart'; +import 'package:tallee/data/models/team.dart'; class DataTransferService { /// Deletes all data from the database. @@ -40,33 +40,39 @@ class DataTransferService { 'players': players.map((p) => p.toJson()).toList(), 'games': games.map((g) => g.toJson()).toList(), 'groups': groups - .map((g) => { - 'id': g.id, - 'name': g.name, - 'description': g.description, - 'createdAt': g.createdAt.toIso8601String(), - 'memberIds': (g.members).map((m) => m.id).toList(), - }) + .map( + (g) => { + 'id': g.id, + 'name': g.name, + 'description': g.description, + 'createdAt': g.createdAt.toIso8601String(), + 'memberIds': (g.members).map((m) => m.id).toList(), + }, + ) .toList(), 'teams': teams - .map((t) => { - 'id': t.id, - 'name': t.name, - 'createdAt': t.createdAt.toIso8601String(), - 'memberIds': (t.members).map((m) => m.id).toList(), - }) + .map( + (t) => { + 'id': t.id, + 'name': t.name, + 'createdAt': t.createdAt.toIso8601String(), + 'memberIds': (t.members).map((m) => m.id).toList(), + }, + ) .toList(), 'matches': matches - .map((m) => { - 'id': m.id, - 'name': m.name, - 'createdAt': m.createdAt.toIso8601String(), - 'endedAt': m.endedAt?.toIso8601String(), - 'gameId': m.game.id, - 'groupId': m.group?.id, - 'playerIds': m.players.map((p) => p.id).toList(), - 'notes': m.notes, - }) + .map( + (m) => { + 'id': m.id, + 'name': m.name, + 'createdAt': m.createdAt.toIso8601String(), + 'endedAt': m.endedAt?.toIso8601String(), + 'gameId': m.game.id, + 'groupId': m.group?.id, + 'playerIds': m.players.map((p) => p.id).toList(), + 'notes': m.notes, + }, + ) .toList(), }; @@ -79,9 +85,9 @@ class DataTransferService { /// [jsonString] The JSON string to be exported. /// [fileName] The desired name for the exported file (without extension). static Future exportData( - String jsonString, - String fileName - ) async { + String jsonString, + String fileName, + ) async { try { final bytes = Uint8List.fromList(utf8.encode(jsonString)); final path = await FilePicker.platform.saveFile( @@ -94,7 +100,6 @@ class DataTransferService { } else { return ExportResult.success; } - } catch (e, stack) { print('[exportData] $e'); print(stack); @@ -122,13 +127,19 @@ class DataTransferService { final isValid = await _validateJsonSchema(jsonString); if (!isValid) return ImportResult.invalidSchema; - final Map decoded = json.decode(jsonString) as Map; + final Map decoded = + json.decode(jsonString) as Map; - final List playersJson = (decoded['players'] as List?) ?? []; - final List gamesJson = (decoded['games'] as List?) ?? []; - final List groupsJson = (decoded['groups'] as List?) ?? []; - final List teamsJson = (decoded['teams'] as List?) ?? []; - final List matchesJson = (decoded['matches'] as List?) ?? []; + final List playersJson = + (decoded['players'] as List?) ?? []; + final List gamesJson = + (decoded['games'] as List?) ?? []; + final List groupsJson = + (decoded['groups'] as List?) ?? []; + final List teamsJson = + (decoded['teams'] as List?) ?? []; + final List matchesJson = + (decoded['matches'] as List?) ?? []; // Import Players final List importedPlayers = playersJson @@ -151,7 +162,8 @@ class DataTransferService { // Import Groups final List importedGroups = groupsJson.map((g) { final map = g as Map; - final memberIds = (map['memberIds'] as List? ?? []).cast(); + final memberIds = (map['memberIds'] as List? ?? []) + .cast(); final members = memberIds .map((id) => playerById[id]) @@ -174,7 +186,8 @@ class DataTransferService { // Import Teams final List importedTeams = teamsJson.map((t) { final map = t as Map; - final memberIds = (map['memberIds'] as List? ?? []).cast(); + final memberIds = (map['memberIds'] as List? ?? []) + .cast(); final members = memberIds .map((id) => playerById[id]) @@ -195,8 +208,11 @@ class DataTransferService { final String gameId = map['gameId'] as String; final String? groupId = map['groupId'] as String?; - final List playerIds = (map['playerIds'] as List? ?? []).cast(); - final DateTime? endedAt = map['endedAt'] != null ? DateTime.parse(map['endedAt'] as String) : null; + final List playerIds = + (map['playerIds'] as List? ?? []).cast(); + final DateTime? endedAt = map['endedAt'] != null + ? DateTime.parse(map['endedAt'] as String) + : null; final game = gameById[gameId]; final group = (groupId == null) ? null : groupById[groupId]; @@ -208,7 +224,15 @@ class DataTransferService { return Match( id: map['id'] as String, name: map['name'] as String, - game: game ?? Game(name: 'Unknown', ruleset: Ruleset.singleWinner, description: '', color: GameColor.blue, icon: ''), + game: + game ?? + Game( + name: 'Unknown', + ruleset: Ruleset.singleWinner, + description: '', + color: GameColor.blue, + icon: '', + ), group: group, players: players, createdAt: DateTime.parse(map['createdAt'] as String), @@ -266,4 +290,4 @@ class DataTransferService { return false; } } -} \ No newline at end of file +} diff --git a/test/db_tests/aggregates/group_test.dart b/test/db_tests/aggregates/group_test.dart index a671232..5e713c4 100644 --- a/test/db_tests/aggregates/group_test.dart +++ b/test/db_tests/aggregates/group_test.dart @@ -3,8 +3,8 @@ import 'package:drift/drift.dart' hide isNull; import 'package:drift/native.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:tallee/data/db/database.dart'; -import 'package:tallee/data/dto/group.dart'; -import 'package:tallee/data/dto/player.dart'; +import 'package:tallee/data/models/group.dart'; +import 'package:tallee/data/models/player.dart'; void main() { late AppDatabase database; @@ -62,7 +62,6 @@ void main() { await database.close(); }); group('Group Tests', () { - // Verifies that a single group can be added and retrieved with all fields and members intact. test('Adding and fetching a single group works correctly', () async { await database.groupDao.addGroup(group: testGroup1); @@ -277,20 +276,20 @@ void main() { }); // Verifies that updateGroupDescription returns false for a non-existent group. - test('updateGroupDescription returns false for non-existent group', - () async { - final updated = await database.groupDao.updateGroupDescription( - groupId: 'non-existent-id', - newDescription: 'New Description', - ); - expect(updated, false); - }); + test( + 'updateGroupDescription returns false for non-existent group', + () async { + final updated = await database.groupDao.updateGroupDescription( + groupId: 'non-existent-id', + newDescription: 'New Description', + ); + expect(updated, false); + }, + ); // Verifies that deleteAllGroups removes all groups from the database. test('deleteAllGroups removes all groups', () async { - await database.groupDao.addGroupsAsList( - groups: [testGroup1, testGroup2], - ); + await database.groupDao.addGroupsAsList(groups: [testGroup1, testGroup2]); final countBefore = await database.groupDao.getGroupCount(); expect(countBefore, 2); diff --git a/test/db_tests/aggregates/match_test.dart b/test/db_tests/aggregates/match_test.dart index f5fbeb6..45c7de3 100644 --- a/test/db_tests/aggregates/match_test.dart +++ b/test/db_tests/aggregates/match_test.dart @@ -4,10 +4,10 @@ import 'package:drift/native.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:tallee/core/enums.dart'; import 'package:tallee/data/db/database.dart'; -import 'package:tallee/data/dto/game.dart'; -import 'package:tallee/data/dto/group.dart'; -import 'package:tallee/data/dto/match.dart'; -import 'package:tallee/data/dto/player.dart'; +import 'package:tallee/data/models/game.dart'; +import 'package:tallee/data/models/group.dart'; +import 'package:tallee/data/models/match.dart'; +import 'package:tallee/data/models/player.dart'; void main() { late AppDatabase database; diff --git a/test/db_tests/aggregates/team_test.dart b/test/db_tests/aggregates/team_test.dart index 17ceff9..9fcf9bb 100644 --- a/test/db_tests/aggregates/team_test.dart +++ b/test/db_tests/aggregates/team_test.dart @@ -2,12 +2,12 @@ import 'package:clock/clock.dart'; import 'package:drift/drift.dart'; import 'package:drift/native.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:tallee/data/db/database.dart'; -import 'package:tallee/data/dto/game.dart'; -import 'package:tallee/data/dto/match.dart'; -import 'package:tallee/data/dto/player.dart'; -import 'package:tallee/data/dto/team.dart'; import 'package:tallee/core/enums.dart'; +import 'package:tallee/data/db/database.dart'; +import 'package:tallee/data/models/game.dart'; +import 'package:tallee/data/models/match.dart'; +import 'package:tallee/data/models/player.dart'; +import 'package:tallee/data/models/team.dart'; void main() { late AppDatabase database; @@ -37,20 +37,23 @@ void main() { testPlayer2 = Player(name: 'Bob', description: ''); testPlayer3 = Player(name: 'Charlie', description: ''); testPlayer4 = Player(name: 'Diana', description: ''); - testTeam1 = Team( - name: 'Team Alpha', - members: [testPlayer1, testPlayer2], + testTeam1 = Team(name: 'Team Alpha', members: [testPlayer1, testPlayer2]); + testTeam2 = Team(name: 'Team Beta', members: [testPlayer3, testPlayer4]); + testTeam3 = Team(name: 'Team Gamma', members: [testPlayer1, testPlayer3]); + testGame1 = Game( + name: 'Game 1', + ruleset: Ruleset.singleWinner, + description: 'Test game 1', + color: GameColor.blue, + icon: '', ); - testTeam2 = Team( - name: 'Team Beta', - members: [testPlayer3, testPlayer4], + testGame2 = Game( + name: 'Game 2', + ruleset: Ruleset.highestScore, + description: 'Test game 2', + color: GameColor.red, + icon: '', ); - testTeam3 = Team( - name: 'Team Gamma', - members: [testPlayer1, testPlayer3], - ); - testGame1 = Game(name: 'Game 1', ruleset: Ruleset.singleWinner, description: 'Test game 1', color: GameColor.blue, icon: ''); - testGame2 = Game(name: 'Game 2', ruleset: Ruleset.highestScore, description: 'Test game 2', color: GameColor.red, icon: ''); }); await database.playerDao.addPlayersAsList( @@ -65,7 +68,6 @@ void main() { }); group('Team Tests', () { - // Verifies that a single team can be added and retrieved with all fields intact. test('Adding and fetching a single team works correctly', () async { final added = await database.teamDao.addTeam(team: testTeam1); @@ -285,10 +287,7 @@ void main() { test('Updating team name to empty string works', () async { await database.teamDao.addTeam(team: testTeam1); - await database.teamDao.updateTeamName( - teamId: testTeam1.id, - newName: '', - ); + await database.teamDao.updateTeamName(teamId: testTeam1.id, newName: ''); final updatedTeam = await database.teamDao.getTeamById( teamId: testTeam1.id, @@ -350,9 +349,7 @@ void main() { await database.matchDao.addMatch(match: match2); // Add teams to database - await database.teamDao.addTeamsAsList( - teams: [testTeam1, testTeam3], - ); + await database.teamDao.addTeamsAsList(teams: [testTeam1, testTeam3]); // Associate players with teams through match1 // testTeam1: player1, player2 @@ -420,10 +417,11 @@ void main() { final allTeams = await database.teamDao.getAllTeams(); expect(allTeams.length, 3); - expect( - allTeams.map((t) => t.id).toSet(), - {testTeam1.id, testTeam2.id, testTeam3.id}, - ); + expect(allTeams.map((t) => t.id).toSet(), { + testTeam1.id, + testTeam2.id, + testTeam3.id, + }); }); // Verifies that teamExists returns false for deleted teams. @@ -462,9 +460,7 @@ void main() { // Verifies that addTeam after deleteAllTeams works correctly. test('Adding team after deleteAllTeams works correctly', () async { - await database.teamDao.addTeamsAsList( - teams: [testTeam1, testTeam2], - ); + await database.teamDao.addTeamsAsList(teams: [testTeam1, testTeam2]); expect(await database.teamDao.getTeamCount(), 2); await database.teamDao.deleteAllTeams(); @@ -524,4 +520,4 @@ void main() { expect(fetchedTeam.createdAt, testTeam1.createdAt); }); }); -} \ No newline at end of file +} diff --git a/test/db_tests/entities/game_test.dart b/test/db_tests/entities/game_test.dart index 924a60b..b00dba1 100644 --- a/test/db_tests/entities/game_test.dart +++ b/test/db_tests/entities/game_test.dart @@ -4,7 +4,7 @@ import 'package:drift/native.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:tallee/core/enums.dart'; import 'package:tallee/data/db/database.dart'; -import 'package:tallee/data/dto/game.dart'; +import 'package:tallee/data/models/game.dart'; void main() { late AppDatabase database; @@ -54,7 +54,6 @@ void main() { }); group('Game Tests', () { - // Verifies that getAllGames returns an empty list when the database has no games. test('getAllGames returns empty list when no games exist', () async { final allGames = await database.gameDao.getAllGames(); @@ -106,7 +105,7 @@ void main() { // Verifies that getGameById throws a StateError when the game doesn't exist. test('getGameById throws exception for non-existent game', () async { expect( - () => database.gameDao.getGameById(gameId: 'non-existent-id'), + () => database.gameDao.getGameById(gameId: 'non-existent-id'), throwsA(isA()), ); }); @@ -134,7 +133,13 @@ void main() { // Verifies that a game with empty optional fields can be added and retrieved. test('addGame handles game with null optional fields', () async { - final gameWithNulls = Game(name: 'Simple Game', ruleset: Ruleset.lowestScore, description: 'A simple game', color: GameColor.green, icon: ''); + final gameWithNulls = Game( + name: 'Simple Game', + ruleset: Ruleset.lowestScore, + description: 'A simple game', + color: GameColor.green, + icon: '', + ); final result = await database.gameDao.addGame(game: gameWithNulls); expect(result, true); @@ -419,9 +424,7 @@ void main() { // Verifies that getGameCount updates correctly after deleting a game. test('getGameCount updates correctly after deletion', () async { - await database.gameDao.addGamesAsList( - games: [testGame1, testGame2], - ); + await database.gameDao.addGamesAsList(games: [testGame1, testGame2]); final countBefore = await database.gameDao.getGameCount(); expect(countBefore, 2); diff --git a/test/db_tests/entities/player_test.dart b/test/db_tests/entities/player_test.dart index 9d7fa77..3042b33 100644 --- a/test/db_tests/entities/player_test.dart +++ b/test/db_tests/entities/player_test.dart @@ -3,7 +3,7 @@ import 'package:drift/drift.dart' hide isNull; import 'package:drift/native.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:tallee/data/db/database.dart'; -import 'package:tallee/data/dto/player.dart'; +import 'package:tallee/data/models/player.dart'; void main() { late AppDatabase database; @@ -35,7 +35,6 @@ void main() { }); group('Player Tests', () { - // Verifies that players can be added and retrieved with all fields intact. test('Adding and fetching single player works correctly', () async { await database.playerDao.addPlayer(player: testPlayer1); @@ -264,16 +263,22 @@ void main() { }); // Verifies that a player with special characters in name is stored correctly. - test('Player with special characters in name is stored correctly', () async { - final specialPlayer = Player(name: 'Test!@#\$%^&*()_+-=[]{}|;\':",.<>?/`~', description: ''); + test( + 'Player with special characters in name is stored correctly', + () async { + final specialPlayer = Player( + name: 'Test!@#\$%^&*()_+-=[]{}|;\':",.<>?/`~', + description: '', + ); - await database.playerDao.addPlayer(player: specialPlayer); + await database.playerDao.addPlayer(player: specialPlayer); - final fetchedPlayer = await database.playerDao.getPlayerById( - playerId: specialPlayer.id, - ); - expect(fetchedPlayer.name, specialPlayer.name); - }); + final fetchedPlayer = await database.playerDao.getPlayerById( + playerId: specialPlayer.id, + ); + expect(fetchedPlayer.name, specialPlayer.name); + }, + ); // Verifies that a player with description is stored correctly. test('Player with description is stored correctly', () async { @@ -293,7 +298,10 @@ void main() { // Verifies that a player with null description is stored correctly. test('Player with null description is stored correctly', () async { - final playerWithoutDescription = Player(name: 'No Description Player', description: ''); + final playerWithoutDescription = Player( + name: 'No Description Player', + description: '', + ); await database.playerDao.addPlayer(player: playerWithoutDescription); diff --git a/test/db_tests/relationships/player_group_test.dart b/test/db_tests/relationships/player_group_test.dart index 051daf8..7004e17 100644 --- a/test/db_tests/relationships/player_group_test.dart +++ b/test/db_tests/relationships/player_group_test.dart @@ -3,8 +3,8 @@ import 'package:drift/drift.dart'; import 'package:drift/native.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:tallee/data/db/database.dart'; -import 'package:tallee/data/dto/group.dart'; -import 'package:tallee/data/dto/player.dart'; +import 'package:tallee/data/models/group.dart'; +import 'package:tallee/data/models/player.dart'; void main() { late AppDatabase database; @@ -42,7 +42,6 @@ void main() { }); group('Player-Group Tests', () { - // Verifies that a player can be added to an existing group and isPlayerInGroup returns true. test('Adding a player to a group works correctly', () async { await database.groupDao.addGroup(group: testGroup); @@ -127,67 +126,83 @@ void main() { }); // Verifies that addPlayerToGroup returns false when player already in group. - test('addPlayerToGroup returns false when player already in group', () async { - await database.groupDao.addGroup(group: testGroup); + test( + 'addPlayerToGroup returns false when player already in group', + () async { + await database.groupDao.addGroup(group: testGroup); - // testPlayer1 is already in testGroup via group creation - final result = await database.playerGroupDao.addPlayerToGroup( - player: testPlayer1, - groupId: testGroup.id, - ); + // testPlayer1 is already in testGroup via group creation + final result = await database.playerGroupDao.addPlayerToGroup( + player: testPlayer1, + groupId: testGroup.id, + ); - expect(result, false); - }); + expect(result, false); + }, + ); // Verifies that addPlayerToGroup adds player to player table if not exists. - test('addPlayerToGroup adds player to player table if not exists', () async { - await database.groupDao.addGroup(group: testGroup); + test( + 'addPlayerToGroup adds player to player table if not exists', + () async { + await database.groupDao.addGroup(group: testGroup); - // testPlayer4 is not in the database yet - var playerExists = await database.playerDao.playerExists( - playerId: testPlayer4.id, - ); - expect(playerExists, false); + // testPlayer4 is not in the database yet + var playerExists = await database.playerDao.playerExists( + playerId: testPlayer4.id, + ); + expect(playerExists, false); - await database.playerGroupDao.addPlayerToGroup( - player: testPlayer4, - groupId: testGroup.id, - ); + await database.playerGroupDao.addPlayerToGroup( + player: testPlayer4, + groupId: testGroup.id, + ); - // Now player should exist in player table - playerExists = await database.playerDao.playerExists( - playerId: testPlayer4.id, - ); - expect(playerExists, true); - }); + // Now player should exist in player table + playerExists = await database.playerDao.playerExists( + playerId: testPlayer4.id, + ); + expect(playerExists, true); + }, + ); // Verifies that removePlayerFromGroup returns false for non-existent player. - test('removePlayerFromGroup returns false for non-existent player', () async { - await database.groupDao.addGroup(group: testGroup); + test( + 'removePlayerFromGroup returns false for non-existent player', + () async { + await database.groupDao.addGroup(group: testGroup); - final result = await database.playerGroupDao.removePlayerFromGroup( - playerId: 'non-existent-player-id', - groupId: testGroup.id, - ); + final result = await database.playerGroupDao.removePlayerFromGroup( + playerId: 'non-existent-player-id', + groupId: testGroup.id, + ); - expect(result, false); - }); + expect(result, false); + }, + ); // Verifies that removePlayerFromGroup returns false for non-existent group. - test('removePlayerFromGroup returns false for non-existent group', () async { - await database.playerDao.addPlayer(player: testPlayer1); + test( + 'removePlayerFromGroup returns false for non-existent group', + () async { + await database.playerDao.addPlayer(player: testPlayer1); - final result = await database.playerGroupDao.removePlayerFromGroup( - playerId: testPlayer1.id, - groupId: 'non-existent-group-id', - ); + final result = await database.playerGroupDao.removePlayerFromGroup( + playerId: testPlayer1.id, + groupId: 'non-existent-group-id', + ); - expect(result, false); - }); + expect(result, false); + }, + ); // Verifies that getPlayersOfGroup returns empty list for group with no members. test('getPlayersOfGroup returns empty list for empty group', () async { - final emptyGroup = Group(name: 'Empty Group', description: '', members: []); + final emptyGroup = Group( + name: 'Empty Group', + description: '', + members: [], + ); await database.groupDao.addGroup(group: emptyGroup); final players = await database.playerGroupDao.getPlayersOfGroup( @@ -198,13 +213,16 @@ void main() { }); // Verifies that getPlayersOfGroup returns empty list for non-existent group. - test('getPlayersOfGroup returns empty list for non-existent group', () async { - final players = await database.playerGroupDao.getPlayersOfGroup( - groupId: 'non-existent-group-id', - ); + test( + 'getPlayersOfGroup returns empty list for non-existent group', + () async { + final players = await database.playerGroupDao.getPlayersOfGroup( + groupId: 'non-existent-group-id', + ); - expect(players, isEmpty); - }); + expect(players, isEmpty); + }, + ); // Verifies that removing all players from a group leaves the group empty. test('Removing all players from a group leaves group empty', () async { @@ -231,7 +249,11 @@ void main() { // Verifies that a player can be in multiple groups. test('Player can be in multiple groups', () async { - final secondGroup = Group(name: 'Second Group', description: '', members: []); + final secondGroup = Group( + name: 'Second Group', + description: '', + members: [], + ); await database.groupDao.addGroup(group: testGroup); await database.groupDao.addGroup(group: secondGroup); @@ -255,29 +277,36 @@ void main() { }); // Verifies that removing player from one group doesn't affect other groups. - test('Removing player from one group does not affect other groups', () async { - final secondGroup = Group(name: 'Second Group', description: '', members: [testPlayer1]); - await database.groupDao.addGroup(group: testGroup); - await database.groupDao.addGroup(group: secondGroup); + test( + 'Removing player from one group does not affect other groups', + () async { + final secondGroup = Group( + name: 'Second Group', + description: '', + members: [testPlayer1], + ); + await database.groupDao.addGroup(group: testGroup); + await database.groupDao.addGroup(group: secondGroup); - // Remove testPlayer1 from testGroup - await database.playerGroupDao.removePlayerFromGroup( - playerId: testPlayer1.id, - groupId: testGroup.id, - ); + // Remove testPlayer1 from testGroup + await database.playerGroupDao.removePlayerFromGroup( + playerId: testPlayer1.id, + groupId: testGroup.id, + ); - final inFirstGroup = await database.playerGroupDao.isPlayerInGroup( - playerId: testPlayer1.id, - groupId: testGroup.id, - ); - final inSecondGroup = await database.playerGroupDao.isPlayerInGroup( - playerId: testPlayer1.id, - groupId: secondGroup.id, - ); + final inFirstGroup = await database.playerGroupDao.isPlayerInGroup( + playerId: testPlayer1.id, + groupId: testGroup.id, + ); + final inSecondGroup = await database.playerGroupDao.isPlayerInGroup( + playerId: testPlayer1.id, + groupId: secondGroup.id, + ); - expect(inFirstGroup, false); - expect(inSecondGroup, true); - }); + expect(inFirstGroup, false); + expect(inSecondGroup, true); + }, + ); // Verifies that addPlayerToGroup returns true on successful addition. test('addPlayerToGroup returns true on successful addition', () async { @@ -293,21 +322,26 @@ void main() { }); // Verifies that removing the same player twice returns false on second attempt. - test('Removing same player twice returns false on second attempt', () async { - await database.groupDao.addGroup(group: testGroup); + test( + 'Removing same player twice returns false on second attempt', + () async { + await database.groupDao.addGroup(group: testGroup); - final firstRemoval = await database.playerGroupDao.removePlayerFromGroup( - playerId: testPlayer1.id, - groupId: testGroup.id, - ); - expect(firstRemoval, true); + final firstRemoval = await database.playerGroupDao + .removePlayerFromGroup( + playerId: testPlayer1.id, + groupId: testGroup.id, + ); + expect(firstRemoval, true); - final secondRemoval = await database.playerGroupDao.removePlayerFromGroup( - playerId: testPlayer1.id, - groupId: testGroup.id, - ); - expect(secondRemoval, false); - }); + final secondRemoval = await database.playerGroupDao + .removePlayerFromGroup( + playerId: testPlayer1.id, + groupId: testGroup.id, + ); + expect(secondRemoval, false); + }, + ); // Verifies that replaceGroupPlayers removes all existing players and replaces with new list. test('replaceGroupPlayers replaces all group members correctly', () async { diff --git a/test/db_tests/relationships/player_match_test.dart b/test/db_tests/relationships/player_match_test.dart index 890e74e..676d72a 100644 --- a/test/db_tests/relationships/player_match_test.dart +++ b/test/db_tests/relationships/player_match_test.dart @@ -4,11 +4,11 @@ import 'package:drift/native.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:tallee/core/enums.dart'; import 'package:tallee/data/db/database.dart'; -import 'package:tallee/data/dto/game.dart'; -import 'package:tallee/data/dto/group.dart'; -import 'package:tallee/data/dto/match.dart'; -import 'package:tallee/data/dto/player.dart'; -import 'package:tallee/data/dto/team.dart'; +import 'package:tallee/data/models/game.dart'; +import 'package:tallee/data/models/group.dart'; +import 'package:tallee/data/models/match.dart'; +import 'package:tallee/data/models/player.dart'; +import 'package:tallee/data/models/team.dart'; void main() { late AppDatabase database; @@ -48,7 +48,13 @@ void main() { description: '', members: [testPlayer1, testPlayer2, testPlayer3], ); - testGame = Game(name: 'Test Game', ruleset: Ruleset.singleWinner, description: 'A test game', color: GameColor.blue, icon: ''); + testGame = Game( + name: 'Test Game', + ruleset: Ruleset.singleWinner, + description: 'A test game', + color: GameColor.blue, + icon: '', + ); testMatchOnlyGroup = Match( name: 'Test Match with Group', game: testGame, @@ -61,14 +67,8 @@ void main() { players: [testPlayer4, testPlayer5, testPlayer6], notes: '', ); - testTeam1 = Team( - name: 'Team Alpha', - members: [testPlayer1, testPlayer2], - ); - testTeam2 = Team( - name: 'Team Beta', - members: [testPlayer3, testPlayer4], - ); + testTeam1 = Team(name: 'Team Alpha', members: [testPlayer1, testPlayer2]); + testTeam2 = Team(name: 'Team Beta', members: [testPlayer3, testPlayer4]); }); await database.playerDao.addPlayersAsList( players: [ @@ -88,7 +88,6 @@ void main() { }); group('Player-Match Tests', () { - // Verifies that matchHasPlayers returns false initially and true after adding a player. test('Match has player works correctly', () async { await database.matchDao.addMatch(match: testMatchOnlyGroup); @@ -153,26 +152,23 @@ void main() { ); expect(result.players.length, testMatchOnlyPlayers.players.length - 1); - final playerExists = result.players.any( - (p) => p.id == playerToRemove.id, - ); + final playerExists = result.players.any((p) => p.id == playerToRemove.id); expect(playerExists, false); }); // Verifies that getPlayersOfMatch returns all players of a match with correct data. test('Retrieving players of a match works correctly', () async { await database.matchDao.addMatch(match: testMatchOnlyPlayers); - final players = await database.playerMatchDao.getPlayersOfMatch( - matchId: testMatchOnlyPlayers.id, - ) ?? []; + final players = + await database.playerMatchDao.getPlayersOfMatch( + matchId: testMatchOnlyPlayers.id, + ) ?? + []; for (int i = 0; i < players.length; i++) { expect(players[i].id, testMatchOnlyPlayers.players[i].id); expect(players[i].name, testMatchOnlyPlayers.players[i].name); - expect( - players[i].createdAt, - testMatchOnlyPlayers.players[i].createdAt, - ); + expect(players[i].createdAt, testMatchOnlyPlayers.players[i].createdAt); } }); @@ -223,10 +219,20 @@ void main() { // Verifies that the same player can be added to multiple different matches. test( 'Adding the same player to separate matches works correctly', - () async { + () async { final playersList = [testPlayer1, testPlayer2, testPlayer3]; - final match1 = Match(name: 'Match 1', game: testGame, players: playersList, notes: ''); - final match2 = Match(name: 'Match 2', game: testGame, players: playersList, notes: ''); + final match1 = Match( + name: 'Match 1', + game: testGame, + players: playersList, + notes: '', + ); + final match2 = Match( + name: 'Match 2', + game: testGame, + players: playersList, + notes: '', + ); await Future.wait([ database.matchDao.addMatch(match: match1), @@ -299,16 +305,19 @@ void main() { }); // Verifies that getPlayerScore returns null for non-existent player-match combination. - test('getPlayerScore returns null for non-existent player in match', () async { - await database.matchDao.addMatch(match: testMatchOnlyGroup); + test( + 'getPlayerScore returns null for non-existent player in match', + () async { + await database.matchDao.addMatch(match: testMatchOnlyGroup); - final score = await database.playerMatchDao.getPlayerScore( - matchId: testMatchOnlyGroup.id, - playerId: 'non-existent-player-id', - ); + final score = await database.playerMatchDao.getPlayerScore( + matchId: testMatchOnlyGroup.id, + playerId: 'non-existent-player-id', + ); - expect(score, isNull); - }); + expect(score, isNull); + }, + ); // Verifies that updatePlayerScore updates the score correctly. test('updatePlayerScore updates score correctly', () async { @@ -331,17 +340,20 @@ void main() { }); // Verifies that updatePlayerScore returns false for non-existent player-match. - test('updatePlayerScore returns false for non-existent player-match', () async { - await database.matchDao.addMatch(match: testMatchOnlyGroup); + test( + 'updatePlayerScore returns false for non-existent player-match', + () async { + await database.matchDao.addMatch(match: testMatchOnlyGroup); - final updated = await database.playerMatchDao.updatePlayerScore( - matchId: testMatchOnlyGroup.id, - playerId: 'non-existent-player-id', - newScore: 50, - ); + final updated = await database.playerMatchDao.updatePlayerScore( + matchId: testMatchOnlyGroup.id, + playerId: 'non-existent-player-id', + newScore: 50, + ); - expect(updated, false); - }); + expect(updated, false); + }, + ); // Verifies that adding a player with teamId works correctly. test('Adding player with teamId works correctly', () async { @@ -431,17 +443,20 @@ void main() { }); // Verifies that updatePlayerTeam returns false for non-existent player-match. - test('updatePlayerTeam returns false for non-existent player-match', () async { - await database.matchDao.addMatch(match: testMatchOnlyGroup); + test( + 'updatePlayerTeam returns false for non-existent player-match', + () async { + await database.matchDao.addMatch(match: testMatchOnlyGroup); - final updated = await database.playerMatchDao.updatePlayerTeam( - matchId: testMatchOnlyGroup.id, - playerId: 'non-existent-player-id', - teamId: testTeam1.id, - ); + final updated = await database.playerMatchDao.updatePlayerTeam( + matchId: testMatchOnlyGroup.id, + playerId: 'non-existent-player-id', + teamId: testTeam1.id, + ); - expect(updated, false); - }); + expect(updated, false); + }, + ); // Verifies that getPlayersInTeam returns empty list for non-existent team. test('getPlayersInTeam returns empty list for non-existent team', () async { @@ -483,16 +498,19 @@ void main() { }); // Verifies that removePlayerFromMatch returns false for non-existent player. - test('removePlayerFromMatch returns false for non-existent player', () async { - await database.matchDao.addMatch(match: testMatchOnlyPlayers); + test( + 'removePlayerFromMatch returns false for non-existent player', + () async { + await database.matchDao.addMatch(match: testMatchOnlyPlayers); - final removed = await database.playerMatchDao.removePlayerFromMatch( - playerId: 'non-existent-player-id', - matchId: testMatchOnlyPlayers.id, - ); + final removed = await database.playerMatchDao.removePlayerFromMatch( + playerId: 'non-existent-player-id', + matchId: testMatchOnlyPlayers.id, + ); - expect(removed, false); - }); + expect(removed, false); + }, + ); // Verifies that adding the same player twice to the same match is ignored. test('Adding same player twice to same match is ignored', () async { @@ -528,27 +546,30 @@ void main() { }); // Verifies that updatePlayersFromMatch with empty list removes all players. - test('updatePlayersFromMatch with empty list removes all players', () async { - await database.matchDao.addMatch(match: testMatchOnlyPlayers); + test( + 'updatePlayersFromMatch with empty list removes all players', + () async { + await database.matchDao.addMatch(match: testMatchOnlyPlayers); - // Verify players exist initially - var players = await database.playerMatchDao.getPlayersOfMatch( - matchId: testMatchOnlyPlayers.id, - ); - expect(players?.length, 3); + // Verify players exist initially + var players = await database.playerMatchDao.getPlayersOfMatch( + matchId: testMatchOnlyPlayers.id, + ); + expect(players?.length, 3); - // Update with empty list - await database.playerMatchDao.updatePlayersFromMatch( - matchId: testMatchOnlyPlayers.id, - newPlayer: [], - ); + // Update with empty list + await database.playerMatchDao.updatePlayersFromMatch( + matchId: testMatchOnlyPlayers.id, + newPlayer: [], + ); - // Verify all players are removed - players = await database.playerMatchDao.getPlayersOfMatch( - matchId: testMatchOnlyPlayers.id, - ); - expect(players, isNull); - }); + // Verify all players are removed + players = await database.playerMatchDao.getPlayersOfMatch( + matchId: testMatchOnlyPlayers.id, + ); + expect(players, isNull); + }, + ); // Verifies that updatePlayersFromMatch with same players makes no changes. test('updatePlayersFromMatch with same players makes no changes', () async { @@ -702,16 +723,19 @@ void main() { }); // Verifies that getPlayersInTeam returns empty list for non-existent match. - test('getPlayersInTeam returns empty list for non-existent match', () async { - await database.teamDao.addTeam(team: testTeam1); + test( + 'getPlayersInTeam returns empty list for non-existent match', + () async { + await database.teamDao.addTeam(team: testTeam1); - final players = await database.playerMatchDao.getPlayersInTeam( - matchId: 'non-existent-match-id', - teamId: testTeam1.id, - ); + final players = await database.playerMatchDao.getPlayersInTeam( + matchId: 'non-existent-match-id', + teamId: testTeam1.id, + ); - expect(players.isEmpty, true); - }); + expect(players.isEmpty, true); + }, + ); // Verifies that players in different teams within the same match are returned correctly. test('Players in different teams within same match are separate', () async { @@ -759,8 +783,18 @@ void main() { // Verifies that removePlayerFromMatch does not affect other matches. test('removePlayerFromMatch does not affect other matches', () async { final playersList = [testPlayer1, testPlayer2]; - final match1 = Match(name: 'Match 1', game: testGame, players: playersList, notes: ''); - final match2 = Match(name: 'Match 2', game: testGame, players: playersList, notes: ''); + final match1 = Match( + name: 'Match 1', + game: testGame, + players: playersList, + notes: '', + ); + final match2 = Match( + name: 'Match 2', + game: testGame, + players: playersList, + notes: '', + ); await Future.wait([ database.matchDao.addMatch(match: match1), @@ -792,8 +826,18 @@ void main() { // Verifies that updating scores for players in different matches are independent. test('Player scores are independent across matches', () async { final playersList = [testPlayer1]; - final match1 = Match(name: 'Match 1', game: testGame, players: playersList, notes: ''); - final match2 = Match(name: 'Match 2', game: testGame, players: playersList, notes: ''); + final match1 = Match( + name: 'Match 1', + game: testGame, + players: playersList, + notes: '', + ); + final match2 = Match( + name: 'Match 2', + game: testGame, + players: playersList, + notes: '', + ); await Future.wait([ database.matchDao.addMatch(match: match1), @@ -829,16 +873,19 @@ void main() { }); // Verifies that updatePlayersFromMatch on non-existent match fails with constraint error. - test('updatePlayersFromMatch on non-existent match fails with foreign key constraint', () async { - // Should throw due to foreign key constraint - match doesn't exist - await expectLater( - database.playerMatchDao.updatePlayersFromMatch( - matchId: 'non-existent-match-id', - newPlayer: [testPlayer1, testPlayer2], - ), - throwsA(anything), - ); - }); + test( + 'updatePlayersFromMatch on non-existent match fails with foreign key constraint', + () async { + // Should throw due to foreign key constraint - match doesn't exist + await expectLater( + database.playerMatchDao.updatePlayersFromMatch( + matchId: 'non-existent-match-id', + newPlayer: [testPlayer1, testPlayer2], + ), + throwsA(anything), + ); + }, + ); // Verifies that a player can be in a match without being assigned to a team. test('Player can exist in match without team assignment', () async { diff --git a/test/db_tests/values/score_test.dart b/test/db_tests/values/score_test.dart index 2ad4671..381b7a7 100644 --- a/test/db_tests/values/score_test.dart +++ b/test/db_tests/values/score_test.dart @@ -2,11 +2,11 @@ import 'package:clock/clock.dart'; import 'package:drift/drift.dart' hide isNull, isNotNull; import 'package:drift/native.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:tallee/data/db/database.dart'; -import 'package:tallee/data/dto/game.dart'; -import 'package:tallee/data/dto/match.dart'; -import 'package:tallee/data/dto/player.dart'; import 'package:tallee/core/enums.dart'; +import 'package:tallee/data/db/database.dart'; +import 'package:tallee/data/models/game.dart'; +import 'package:tallee/data/models/match.dart'; +import 'package:tallee/data/models/player.dart'; void main() { late AppDatabase database; @@ -32,7 +32,13 @@ void main() { testPlayer1 = Player(name: 'Alice', description: ''); testPlayer2 = Player(name: 'Bob', description: ''); testPlayer3 = Player(name: 'Charlie', description: ''); - testGame = Game(name: 'Test Game', ruleset: Ruleset.singleWinner, description: 'A test game', color: GameColor.blue, icon: ''); + testGame = Game( + name: 'Test Game', + ruleset: Ruleset.singleWinner, + description: 'A test game', + color: GameColor.blue, + icon: '', + ); testMatch1 = Match( name: 'Test Match 1', game: testGame, @@ -60,7 +66,6 @@ void main() { }); group('Score Tests', () { - // Verifies that a score can be added and retrieved with all fields intact. test('Adding and fetching a score works correctly', () async { await database.scoreDao.addScore( @@ -431,13 +436,16 @@ void main() { }); // Verifies that getScoresForMatch returns empty list for match with no scores. - test('Getting scores for match with no scores returns empty list', () async { - final scores = await database.scoreDao.getScoresForMatch( - matchId: testMatch1.id, - ); + test( + 'Getting scores for match with no scores returns empty list', + () async { + final scores = await database.scoreDao.getScoresForMatch( + matchId: testMatch1.id, + ); - expect(scores.isEmpty, true); - }); + expect(scores.isEmpty, true); + }, + ); // Verifies that getPlayerScoresInMatch returns empty list when player has no scores. test('Getting player scores with no scores returns empty list', () async { @@ -666,46 +674,58 @@ void main() { }); // Verifies that updating one player's score doesn't affect another player's score in same round. - test('Updating one player score does not affect other players in same round', () async { - await database.scoreDao.addScore( - playerId: testPlayer1.id, - matchId: testMatch1.id, - roundNumber: 1, - score: 10, - change: 10, - ); - await database.scoreDao.addScore( - playerId: testPlayer2.id, - matchId: testMatch1.id, - roundNumber: 1, - score: 20, - change: 20, - ); - await database.scoreDao.addScore( - playerId: testPlayer3.id, - matchId: testMatch1.id, - roundNumber: 1, - score: 30, - change: 30, - ); + test( + 'Updating one player score does not affect other players in same round', + () async { + await database.scoreDao.addScore( + playerId: testPlayer1.id, + matchId: testMatch1.id, + roundNumber: 1, + score: 10, + change: 10, + ); + await database.scoreDao.addScore( + playerId: testPlayer2.id, + matchId: testMatch1.id, + roundNumber: 1, + score: 20, + change: 20, + ); + await database.scoreDao.addScore( + playerId: testPlayer3.id, + matchId: testMatch1.id, + roundNumber: 1, + score: 30, + change: 30, + ); - await database.scoreDao.updateScore( - playerId: testPlayer2.id, - matchId: testMatch1.id, - roundNumber: 1, - newScore: 99, - newChange: 89, - ); + await database.scoreDao.updateScore( + playerId: testPlayer2.id, + matchId: testMatch1.id, + roundNumber: 1, + newScore: 99, + newChange: 89, + ); - final scores = await database.scoreDao.getScoresForMatch( - matchId: testMatch1.id, - ); + final scores = await database.scoreDao.getScoresForMatch( + matchId: testMatch1.id, + ); - expect(scores.length, 3); - expect(scores.where((s) => s.playerId == testPlayer1.id).first.score, 10); - expect(scores.where((s) => s.playerId == testPlayer2.id).first.score, 99); - expect(scores.where((s) => s.playerId == testPlayer3.id).first.score, 30); - }); + expect(scores.length, 3); + expect( + scores.where((s) => s.playerId == testPlayer1.id).first.score, + 10, + ); + expect( + scores.where((s) => s.playerId == testPlayer2.id).first.score, + 99, + ); + expect( + scores.where((s) => s.playerId == testPlayer3.id).first.score, + 30, + ); + }, + ); // Verifies that deleting a player's scores only affects that specific player. test('Deleting player scores only affects target player', () async { @@ -724,9 +744,7 @@ void main() { change: 20, ); - await database.scoreDao.deleteScoresForPlayer( - playerId: testPlayer1.id, - ); + await database.scoreDao.deleteScoresForPlayer(playerId: testPlayer1.id); final match1Scores = await database.scoreDao.getScoresForMatch( matchId: testMatch1.id,