From 8f4254748bce1f1d7406ac58bff4f4b6c1f74b43 Mon Sep 17 00:00:00 2001 From: gelbeinhalb Date: Tue, 12 May 2026 20:33:02 +0200 Subject: [PATCH] deleted groups get ignored when includeDeleted is false --- lib/data/dao/group_dao.dart | 38 +++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/lib/data/dao/group_dao.dart b/lib/data/dao/group_dao.dart index bffe5a4..fdaa055 100644 --- a/lib/data/dao/group_dao.dart +++ b/lib/data/dao/group_dao.dart @@ -139,8 +139,12 @@ class GroupDao extends DatabaseAccessor with _$GroupDaoMixin { /* Read */ /// Retrieves all groups from the database. - Future> getAllGroups() async { + /// By default, only returns non-deleted groups. + Future> getAllGroups({bool includeDeleted = false}) async { final query = select(groupTable); + if (!includeDeleted) { + query.where((g) => g.deleted.equals(false)); + } final result = await query.get(); return Future.wait( result.map((groupData) async { @@ -159,8 +163,15 @@ class GroupDao extends DatabaseAccessor with _$GroupDaoMixin { } /// Retrieves a [Group] by its [groupId], including its members. - Future getGroupById({required String groupId}) async { + /// By default, only returns non-deleted groups. + Future getGroupById({ + required String groupId, + bool includeDeleted = false, + }) async { final query = select(groupTable)..where((g) => g.id.equals(groupId)); + if (!includeDeleted) { + query.where((g) => g.deleted.equals(false)); + } final result = await query.getSingle(); List members = await db.playerGroupDao.getPlayersOfGroup( @@ -177,18 +188,29 @@ class GroupDao extends DatabaseAccessor with _$GroupDaoMixin { } /// Retrieves the number of groups in the database. - Future getGroupCount() async { - final count = - await (selectOnly(groupTable)..addColumns([groupTable.id.count()])) - .map((row) => row.read(groupTable.id.count())) - .getSingle(); + /// By default, only returns non-deleted groups. + Future getGroupCount({bool includeDeleted = false}) async { + final query = selectOnly(groupTable)..addColumns([groupTable.id.count()]); + if (!includeDeleted) { + query.where(groupTable.deleted.equals(false)); + } + final count = await query + .map((row) => row.read(groupTable.id.count())) + .getSingle(); return count ?? 0; } /// Checks if a group with the given [groupId] exists in the database. + /// By default, only returns non-deleted groups. /// Returns `true` if the group exists, `false` otherwise. - Future groupExists({required String groupId}) async { + Future groupExists({ + required String groupId, + bool includeDeleted = false, + }) async { final query = select(groupTable)..where((g) => g.id.equals(groupId)); + if (!includeDeleted) { + query.where((g) => g.deleted.equals(false)); + } final result = await query.getSingleOrNull(); return result != null; }