deleted groups get ignored when includeDeleted is false

This commit is contained in:
gelbeinhalb
2026-05-12 20:33:02 +02:00
parent 36ad2ab446
commit 8f4254748b

View File

@@ -139,8 +139,12 @@ class GroupDao extends DatabaseAccessor<AppDatabase> with _$GroupDaoMixin {
/* Read */ /* Read */
/// Retrieves all groups from the database. /// Retrieves all groups from the database.
Future<List<Group>> getAllGroups() async { /// By default, only returns non-deleted groups.
Future<List<Group>> getAllGroups({bool includeDeleted = false}) async {
final query = select(groupTable); final query = select(groupTable);
if (!includeDeleted) {
query.where((g) => g.deleted.equals(false));
}
final result = await query.get(); final result = await query.get();
return Future.wait( return Future.wait(
result.map((groupData) async { result.map((groupData) async {
@@ -159,8 +163,15 @@ class GroupDao extends DatabaseAccessor<AppDatabase> with _$GroupDaoMixin {
} }
/// Retrieves a [Group] by its [groupId], including its members. /// Retrieves a [Group] by its [groupId], including its members.
Future<Group> getGroupById({required String groupId}) async { /// By default, only returns non-deleted groups.
Future<Group> getGroupById({
required String groupId,
bool includeDeleted = false,
}) async {
final query = select(groupTable)..where((g) => g.id.equals(groupId)); final query = select(groupTable)..where((g) => g.id.equals(groupId));
if (!includeDeleted) {
query.where((g) => g.deleted.equals(false));
}
final result = await query.getSingle(); final result = await query.getSingle();
List<Player> members = await db.playerGroupDao.getPlayersOfGroup( List<Player> members = await db.playerGroupDao.getPlayersOfGroup(
@@ -177,18 +188,29 @@ class GroupDao extends DatabaseAccessor<AppDatabase> with _$GroupDaoMixin {
} }
/// Retrieves the number of groups in the database. /// Retrieves the number of groups in the database.
Future<int> getGroupCount() async { /// By default, only returns non-deleted groups.
final count = Future<int> getGroupCount({bool includeDeleted = false}) async {
await (selectOnly(groupTable)..addColumns([groupTable.id.count()])) 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())) .map((row) => row.read(groupTable.id.count()))
.getSingle(); .getSingle();
return count ?? 0; return count ?? 0;
} }
/// Checks if a group with the given [groupId] exists in the database. /// 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. /// Returns `true` if the group exists, `false` otherwise.
Future<bool> groupExists({required String groupId}) async { Future<bool> groupExists({
required String groupId,
bool includeDeleted = false,
}) async {
final query = select(groupTable)..where((g) => g.id.equals(groupId)); final query = select(groupTable)..where((g) => g.id.equals(groupId));
if (!includeDeleted) {
query.where((g) => g.deleted.equals(false));
}
final result = await query.getSingleOrNull(); final result = await query.getSingleOrNull();
return result != null; return result != null;
} }