feat(08-01): add isActive filters to CalendarDao, DailyPlanDao, RoomsDao
- CalendarDao: filter all 6 task queries (watchTasksForDate, watchTasksForDateInRoom, watchOverdueTasks, watchOverdueTasksInRoom, getTaskCount, getTaskCountInRoom) by isActive=true - DailyPlanDao: filter all 3 queries (watchAllTasksWithRoomName, getOverdueAndTodayTaskCount, getOverdueTaskCount) by isActive=true - RoomsDao: filter watchRoomWithStats task query by isActive=true - Update migration test: add schema_v3.dart, test v1->v3 and v2->v3 paths - Update database_test schemaVersion assertion to expect 3 - Fix test helpers in home_screen_test and task_list_screen_test to pass isActive=true
This commit is contained in:
@@ -28,7 +28,8 @@ class CalendarDao extends DatabaseAccessor<AppDatabase>
|
||||
]);
|
||||
query.where(
|
||||
tasks.nextDueDate.isBiggerOrEqualValue(startOfDay) &
|
||||
tasks.nextDueDate.isSmallerThanValue(endOfDay),
|
||||
tasks.nextDueDate.isSmallerThanValue(endOfDay) &
|
||||
tasks.isActive.equals(true),
|
||||
);
|
||||
query.orderBy([OrderingTerm.asc(tasks.name)]);
|
||||
|
||||
@@ -45,12 +46,14 @@ class CalendarDao extends DatabaseAccessor<AppDatabase>
|
||||
});
|
||||
}
|
||||
|
||||
/// Returns the total count of tasks across all rooms and dates.
|
||||
/// Returns the total count of active tasks across all rooms and dates.
|
||||
///
|
||||
/// Used by the UI to distinguish first-run empty state from celebration state.
|
||||
Future<int> getTaskCount() async {
|
||||
final countExp = tasks.id.count();
|
||||
final query = selectOnly(tasks)..addColumns([countExp]);
|
||||
final query = selectOnly(tasks)
|
||||
..addColumns([countExp])
|
||||
..where(tasks.isActive.equals(true));
|
||||
final result = await query.getSingle();
|
||||
return result.read(countExp) ?? 0;
|
||||
}
|
||||
@@ -69,7 +72,8 @@ class CalendarDao extends DatabaseAccessor<AppDatabase>
|
||||
query.where(
|
||||
tasks.nextDueDate.isBiggerOrEqualValue(startOfDay) &
|
||||
tasks.nextDueDate.isSmallerThanValue(endOfDay) &
|
||||
tasks.roomId.equals(roomId),
|
||||
tasks.roomId.equals(roomId) &
|
||||
tasks.isActive.equals(true),
|
||||
);
|
||||
query.orderBy([OrderingTerm.asc(tasks.name)]);
|
||||
|
||||
@@ -96,7 +100,10 @@ class CalendarDao extends DatabaseAccessor<AppDatabase>
|
||||
final query = select(tasks).join([
|
||||
innerJoin(rooms, rooms.id.equalsExp(tasks.roomId)),
|
||||
]);
|
||||
query.where(tasks.nextDueDate.isSmallerThanValue(startOfReferenceDay));
|
||||
query.where(
|
||||
tasks.nextDueDate.isSmallerThanValue(startOfReferenceDay) &
|
||||
tasks.isActive.equals(true),
|
||||
);
|
||||
query.orderBy([OrderingTerm.asc(tasks.nextDueDate)]);
|
||||
|
||||
return query.watch().map((rows) {
|
||||
@@ -128,7 +135,8 @@ class CalendarDao extends DatabaseAccessor<AppDatabase>
|
||||
]);
|
||||
query.where(
|
||||
tasks.nextDueDate.isSmallerThanValue(startOfReferenceDay) &
|
||||
tasks.roomId.equals(roomId),
|
||||
tasks.roomId.equals(roomId) &
|
||||
tasks.isActive.equals(true),
|
||||
);
|
||||
query.orderBy([OrderingTerm.asc(tasks.nextDueDate)]);
|
||||
|
||||
@@ -145,7 +153,7 @@ class CalendarDao extends DatabaseAccessor<AppDatabase>
|
||||
});
|
||||
}
|
||||
|
||||
/// Total task count within a specific room.
|
||||
/// Total active task count within a specific room.
|
||||
///
|
||||
/// Used to distinguish first-run empty state from celebration state
|
||||
/// in the room calendar view.
|
||||
@@ -153,7 +161,7 @@ class CalendarDao extends DatabaseAccessor<AppDatabase>
|
||||
final countExp = tasks.id.count();
|
||||
final query = selectOnly(tasks)
|
||||
..addColumns([countExp])
|
||||
..where(tasks.roomId.equals(roomId));
|
||||
..where(tasks.roomId.equals(roomId) & tasks.isActive.equals(true));
|
||||
final result = await query.getSingle();
|
||||
return result.read(countExp) ?? 0;
|
||||
}
|
||||
|
||||
@@ -10,13 +10,14 @@ class DailyPlanDao extends DatabaseAccessor<AppDatabase>
|
||||
with _$DailyPlanDaoMixin {
|
||||
DailyPlanDao(super.attachedDatabase);
|
||||
|
||||
/// Watch all tasks joined with room name, sorted by nextDueDate ascending.
|
||||
/// Includes ALL tasks (overdue, today, future) -- filtering is done in the
|
||||
/// provider layer to avoid multiple queries.
|
||||
/// Watch all active tasks joined with room name, sorted by nextDueDate ascending.
|
||||
/// Includes overdue, today, and future tasks -- filtering is done in the
|
||||
/// provider layer to avoid multiple queries. Excludes soft-deleted tasks.
|
||||
Stream<List<TaskWithRoom>> watchAllTasksWithRoomName() {
|
||||
final query = select(tasks).join([
|
||||
innerJoin(rooms, rooms.id.equalsExp(tasks.roomId)),
|
||||
]);
|
||||
query.where(tasks.isActive.equals(true));
|
||||
query.orderBy([OrderingTerm.asc(tasks.nextDueDate)]);
|
||||
|
||||
return query.watch().map((rows) {
|
||||
@@ -32,24 +33,30 @@ class DailyPlanDao extends DatabaseAccessor<AppDatabase>
|
||||
});
|
||||
}
|
||||
|
||||
/// One-shot count of overdue + today tasks (for notification body).
|
||||
/// One-shot count of overdue + today active tasks (for notification body).
|
||||
Future<int> getOverdueAndTodayTaskCount({DateTime? today}) async {
|
||||
final now = today ?? DateTime.now();
|
||||
final endOfToday = DateTime(now.year, now.month, now.day + 1);
|
||||
final result = await (selectOnly(tasks)
|
||||
..addColumns([tasks.id.count()])
|
||||
..where(tasks.nextDueDate.isSmallerThanValue(endOfToday)))
|
||||
..where(
|
||||
tasks.nextDueDate.isSmallerThanValue(endOfToday) &
|
||||
tasks.isActive.equals(true),
|
||||
))
|
||||
.getSingle();
|
||||
return result.read(tasks.id.count()) ?? 0;
|
||||
}
|
||||
|
||||
/// One-shot count of overdue tasks only (for notification body split).
|
||||
/// One-shot count of overdue active tasks only (for notification body split).
|
||||
Future<int> getOverdueTaskCount({DateTime? today}) async {
|
||||
final now = today ?? DateTime.now();
|
||||
final startOfToday = DateTime(now.year, now.month, now.day);
|
||||
final result = await (selectOnly(tasks)
|
||||
..addColumns([tasks.id.count()])
|
||||
..where(tasks.nextDueDate.isSmallerThanValue(startOfToday)))
|
||||
..where(
|
||||
tasks.nextDueDate.isSmallerThanValue(startOfToday) &
|
||||
tasks.isActive.equals(true),
|
||||
))
|
||||
.getSingle();
|
||||
return result.read(tasks.id.count()) ?? 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user