Bearbeiten und Löschen von Gruppen #148
@@ -1,6 +1,7 @@
|
||||
import 'package:drift/drift.dart';
|
||||
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/match.dart';
|
||||
@@ -8,7 +9,7 @@ import 'package:tallee/data/dto/player.dart';
|
||||
|
||||
part 'group_dao.g.dart';
|
||||
|
||||
@DriftAccessor(tables: [GroupTable, PlayerGroupTable])
|
||||
@DriftAccessor(tables: [GroupTable, PlayerGroupTable, MatchTable])
|
||||
class GroupDao extends DatabaseAccessor<AppDatabase> with _$GroupDaoMixin {
|
||||
GroupDao(super.db);
|
||||
|
||||
@@ -173,9 +174,31 @@ class GroupDao extends DatabaseAccessor<AppDatabase> with _$GroupDaoMixin {
|
||||
}
|
||||
|
||||
/// Retrieves all matches associated with the given [groupId].
|
||||
|
sneeex marked this conversation as resolved
Outdated
|
||||
/// Queries the database directly, filtering by [groupId].
|
||||
Future<List<Match>> getGroupMatches({required String groupId}) async {
|
||||
final matches = await db.matchDao.getAllMatches();
|
||||
return matches.where((match) => match.group?.id == groupId).toList();
|
||||
final query = select(matchTable)..where((m) => m.groupId.equals(groupId));
|
||||
final rows = await query.get();
|
||||
|
||||
return Future.wait(
|
||||
rows.map((row) async {
|
||||
final game = await db.gameDao.getGameById(gameId: row.gameId);
|
||||
final group = await db.groupDao.getGroupById(groupId: groupId);
|
||||
final players =
|
||||
await db.playerMatchDao.getPlayersOfMatch(matchId: row.id) ?? [];
|
||||
final winner = await db.matchDao.getWinner(matchId: row.id);
|
||||
return Match(
|
||||
id: row.id,
|
||||
name: row.name ?? '',
|
||||
game: game,
|
||||
group: group,
|
||||
players: players,
|
||||
notes: row.notes ?? '',
|
||||
createdAt: row.createdAt,
|
||||
endedAt: row.endedAt,
|
||||
winner: winner,
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
/// Deletes the group with the given [id] from the database.
|
||||
|
||||
@@ -8,4 +8,6 @@ mixin _$GroupDaoMixin on DatabaseAccessor<AppDatabase> {
|
||||
$PlayerTableTable get playerTable => attachedDatabase.playerTable;
|
||||
$PlayerGroupTableTable get playerGroupTable =>
|
||||
attachedDatabase.playerGroupTable;
|
||||
$GameTableTable get gameTable => attachedDatabase.gameTable;
|
||||
$MatchTableTable get matchTable => attachedDatabase.matchTable;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user
Du sollst direkt die Datenbankanfrage so gestalten, dass du nur die Matches bekommst, welche die Gruppe enthalten. Das war mein Punkt
so wenig effort wie möglich
ja schlimm
match name soll nicht nullable sein oder?
Eigentlich nicht, das ist schon wieder Fusch am Bau