Updated score and winner handling

This commit is contained in:
2026-04-21 18:38:00 +02:00
parent 522441b0ca
commit 9364f0d9d6
19 changed files with 286 additions and 179 deletions

View File

@@ -2,11 +2,12 @@ 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/db/tables/match_table.dart';
import 'package:tallee/data/models/game.dart';
part 'game_dao.g.dart';
@DriftAccessor(tables: [GameTable])
@DriftAccessor(tables: [MatchTable, GameTable])
class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
GameDao(super.db);
@@ -44,6 +45,25 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
);
}
Future<Game> getGameByMatchId({required String matchId}) async {
final query = select(gameTable).join([
innerJoin(matchTable, matchTable.gameId.equalsExp(gameTable.id)),
])..where(matchTable.id.equals(matchId));
final result = await query.getSingle();
final gameRow = result.readTable(gameTable);
return Game(
id: gameRow.id,
name: gameRow.name,
ruleset: Ruleset.values.firstWhere((e) => e.name == gameRow.ruleset),
description: gameRow.description,
color: GameColor.values.firstWhere((e) => e.name == gameRow.color),
icon: gameRow.icon,
createdAt: gameRow.createdAt,
);
}
/// Adds a new [game] to the database.
/// If a game with the same ID already exists, no action is taken.
/// Returns `true` if the game was added, `false` otherwise.