Added missing dao functions

This commit is contained in:
2026-05-18 22:39:52 +02:00
parent 9a8b93510e
commit 9c5e72e6ed
4 changed files with 27 additions and 13 deletions

View File

@@ -241,6 +241,14 @@ class TeamDao extends DatabaseAccessor<AppDatabase> with _$TeamDaoMixin {
return true;
}
Future<bool> 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<AppDatabase> 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<bool> setWinnerTeam({
required String teamId,
required String matchId,
@@ -268,6 +278,8 @@ class TeamDao extends DatabaseAccessor<AppDatabase> 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<bool> setWinnerTeams({
required List<Team> winners,
required String matchId,
@@ -283,13 +295,14 @@ class TeamDao extends DatabaseAccessor<AppDatabase> with _$TeamDaoMixin {
return success.every((result) => result == true);
}
Future<bool> 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<bool> 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<bool> setLoserTeam({
required String teamId,
required String matchId,
@@ -297,13 +310,17 @@ class TeamDao extends DatabaseAccessor<AppDatabase> 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<bool> 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<bool> setTeamPlacements({
required String matchId,
required List<Team> teams,

View File

@@ -306,10 +306,7 @@ class _MatchResultViewState extends State<MatchResultView> {
Future<bool> _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<MatchResultView> {
Future<bool> _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,

View File

@@ -235,7 +235,7 @@ class _MatchTileState extends State<MatchTile> {
LayoutBuilder(
builder: (context, constraints) {
final useSingleColumn = match.teams!.any(
(team) => team.name.length > 14,
(team) => team.name.length > 10,
);
const spacing = 8.0;

View File

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