WIP: Implementierung von deleted Attribut #204
@@ -139,8 +139,12 @@ class GroupDao extends DatabaseAccessor<AppDatabase> with _$GroupDaoMixin {
|
||||
/* Read */
|
||||
|
||||
/// 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);
|
||||
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<AppDatabase> with _$GroupDaoMixin {
|
||||
}
|
||||
|
||||
/// 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));
|
||||
if (!includeDeleted) {
|
||||
query.where((g) => g.deleted.equals(false));
|
||||
}
|
||||
final result = await query.getSingle();
|
||||
|
||||
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.
|
||||
Future<int> getGroupCount() async {
|
||||
final count =
|
||||
await (selectOnly(groupTable)..addColumns([groupTable.id.count()]))
|
||||
/// By default, only returns non-deleted groups.
|
||||
Future<int> 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<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));
|
||||
if (!includeDeleted) {
|
||||
query.where((g) => g.deleted.equals(false));
|
||||
}
|
||||
final result = await query.getSingleOrNull();
|
||||
return result != null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user