fix(stats): 방문 통계 Provider 자동 갱신 추가
- monthlyVisitStatsProvider: visitRecordsProvider watch 추가 - monthlyCategoryVisitStatsProvider: visitRecordsProvider watch로 변경 - 방문 기록 추가/확인 시 통계가 실시간으로 갱신됨
This commit is contained in:
@@ -31,6 +31,9 @@ final monthlyVisitStatsProvider =
|
|||||||
ref,
|
ref,
|
||||||
params,
|
params,
|
||||||
) async {
|
) async {
|
||||||
|
// visitRecordsProvider를 watch하여 방문 기록 변경 시 자동 갱신
|
||||||
|
await ref.watch(visitRecordsProvider.future);
|
||||||
|
|
||||||
final repository = ref.watch(visitRepositoryProvider);
|
final repository = ref.watch(visitRepositoryProvider);
|
||||||
return repository.getMonthlyVisitStats(params.year, params.month);
|
return repository.getMonthlyVisitStats(params.year, params.month);
|
||||||
});
|
});
|
||||||
@@ -41,13 +44,19 @@ final monthlyCategoryVisitStatsProvider =
|
|||||||
ref,
|
ref,
|
||||||
params,
|
params,
|
||||||
) async {
|
) async {
|
||||||
final repository = ref.watch(visitRepositoryProvider);
|
// visitRecordsProvider를 watch하여 방문 기록 변경 시 자동 갱신
|
||||||
|
final allRecords = await ref.watch(visitRecordsProvider.future);
|
||||||
final restaurants = await ref.watch(restaurantListProvider.future);
|
final restaurants = await ref.watch(restaurantListProvider.future);
|
||||||
|
|
||||||
final records = await repository.getVisitRecordsByDateRange(
|
// 해당 월의 기록만 필터링
|
||||||
startDate: DateTime(params.year, params.month, 1),
|
final startDate = DateTime(params.year, params.month, 1);
|
||||||
endDate: DateTime(params.year, params.month + 1, 0),
|
final endDate = DateTime(params.year, params.month + 1, 0);
|
||||||
);
|
final records = allRecords.where((record) {
|
||||||
|
return record.visitDate.isAfter(
|
||||||
|
startDate.subtract(const Duration(days: 1)),
|
||||||
|
) &&
|
||||||
|
record.visitDate.isBefore(endDate.add(const Duration(days: 1)));
|
||||||
|
}).toList();
|
||||||
|
|
||||||
final categoryCount = <String, int>{};
|
final categoryCount = <String, int>{};
|
||||||
for (final record in records) {
|
for (final record in records) {
|
||||||
|
|||||||
Reference in New Issue
Block a user