From 9c5e72e6ed0373a3a2d44f8c78e147ddae90bb6c Mon Sep 17 00:00:00 2001 From: Felix Kirchner Date: Mon, 18 May 2026 22:39:52 +0200 Subject: [PATCH] Added missing dao functions --- lib/data/dao/team_dao.dart | 29 +++++++++++++++---- .../match_view/match_result_view.dart | 7 ++--- .../widgets/tiles/match_tile.dart | 2 +- pubspec.yaml | 2 +- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/lib/data/dao/team_dao.dart b/lib/data/dao/team_dao.dart index 4efcc74..70ba8b6 100644 --- a/lib/data/dao/team_dao.dart +++ b/lib/data/dao/team_dao.dart @@ -241,6 +241,14 @@ class TeamDao extends DatabaseAccessor with _$TeamDaoMixin { return true; } + Future removeAllTeamScores({required String matchId}) async { + await (update( + teamTable, + )).write(const TeamTableCompanion(score: Value(null))); + await db.scoreEntryDao.deleteAllScoresForMatch(matchId: matchId); + return true; + } + /* Delete */ /// Deletes all teams from the database. @@ -261,6 +269,8 @@ class TeamDao extends DatabaseAccessor with _$TeamDaoMixin { /* Score handling */ + /// Sets the team with the given [teamId] as the winner of the match with the given [matchId] by assigning a score of 1. + /// Returns `true` if the score was updated successfully, `false` otherwise. Future setWinnerTeam({ required String teamId, required String matchId, @@ -268,6 +278,8 @@ class TeamDao extends DatabaseAccessor with _$TeamDaoMixin { return await updateTeamScore(teamId: teamId, matchId: matchId, score: 1); } + /// Sets multiple teams as winners of the match with the given [matchId] by assigning a score of 1 to each team. + /// Returns `true` if all scores were updated successfully, `false` otherwise. Future setWinnerTeams({ required List winners, required String matchId, @@ -283,13 +295,14 @@ class TeamDao extends DatabaseAccessor with _$TeamDaoMixin { return success.every((result) => result == true); } - Future removeWinnerTeam({ - required String teamId, - required String matchId, - }) async { - return await removeScoreForTeam(teamId: teamId, matchId: matchId); + /// Removes the winner status from all Teams with the given [matchId] by setting its score to null. + /// Returns `true` if the score was updated successfully, `false` otherwise. + Future removeWinnerTeam({required String matchId}) async { + return await removeAllTeamScores(matchId: matchId); } + /// Sets the team with the given [teamId] as the loser of the match with the given [matchId] by assigning a score of 0. + /// Returns `true` if the score was updated successfully, `false` otherwise. Future setLoserTeam({ required String teamId, required String matchId, @@ -297,13 +310,17 @@ class TeamDao extends DatabaseAccessor with _$TeamDaoMixin { return await updateTeamScore(teamId: teamId, matchId: matchId, score: 0); } + /// Removes the loser status from the team with the given [teamId] in the match with the given [matchId] by setting its score to null. + /// Returns `true` if the score was updated successfully, `false` otherwise. Future removeLoserTeam({ required String teamId, required String matchId, }) async { - return await removeScoreForTeam(teamId: teamId, matchId: matchId); + return await removeAllTeamScores(matchId: matchId); } + /// Sets the placements for the teams in the match with the given [matchId] by assigning scores based on their order in the [teams] list. + /// Returns `true` if all scores were updated successfully, `false` otherwise. Future setTeamPlacements({ required String matchId, required List teams, 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 a0cbc2a..4f9ab34 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 @@ -306,10 +306,7 @@ class _MatchResultViewState extends State { Future _handleWinner() async { if (isTeamMatch) { if (_selectedTeam == null) { - return await db.teamDao.removeWinnerTeam( - matchId: widget.match.id, - teamId: _selectedTeam!.id, - ); + return await db.teamDao.removeWinnerTeam(matchId: widget.match.id); } else { return await db.teamDao.setWinnerTeam( matchId: widget.match.id, @@ -332,7 +329,7 @@ class _MatchResultViewState extends State { Future _handleWinners() async { if (isTeamMatch) { if (_selectedTeams.isEmpty) { - return await db.scoreEntryDao.removeWinner(matchId: widget.match.id); + return await db.teamDao.removeWinnerTeam(matchId: widget.match.id); } else { return await db.teamDao.setWinnerTeams( matchId: widget.match.id, diff --git a/lib/presentation/widgets/tiles/match_tile.dart b/lib/presentation/widgets/tiles/match_tile.dart index 7c1e801..c3c6b4e 100644 --- a/lib/presentation/widgets/tiles/match_tile.dart +++ b/lib/presentation/widgets/tiles/match_tile.dart @@ -235,7 +235,7 @@ class _MatchTileState extends State { LayoutBuilder( builder: (context, constraints) { final useSingleColumn = match.teams!.any( - (team) => team.name.length > 14, + (team) => team.name.length > 10, ); const spacing = 8.0; diff --git a/pubspec.yaml b/pubspec.yaml index 1310ab9..8d9c1b0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: tallee description: "Tracking App for Card Games" publish_to: 'none' -version: 0.0.30+325 +version: 0.0.30+327 environment: sdk: ^3.8.1