fix(calendar): 월별 방문 카테고리 집계 반영

This commit is contained in:
JiWoong Sul
2025-12-03 18:31:37 +09:00
parent 3f659432e9
commit 637507f02a
2 changed files with 62 additions and 6 deletions

View File

@@ -35,6 +35,34 @@ final monthlyVisitStatsProvider =
return repository.getMonthlyVisitStats(params.year, params.month);
});
/// 월별 카테고리별 방문 통계 Provider
final monthlyCategoryVisitStatsProvider =
FutureProvider.family<Map<String, int>, ({int year, int month})>((
ref,
params,
) async {
final repository = ref.watch(visitRepositoryProvider);
final restaurants = await ref.watch(restaurantListProvider.future);
final records = await repository.getVisitRecordsByDateRange(
startDate: DateTime(params.year, params.month, 1),
endDate: DateTime(params.year, params.month + 1, 0),
);
final categoryCount = <String, int>{};
for (final record in records) {
final restaurant = restaurants
.where((r) => r.id == record.restaurantId)
.firstOrNull;
if (restaurant == null) continue;
categoryCount[restaurant.category] =
(categoryCount[restaurant.category] ?? 0) + 1;
}
return categoryCount;
});
/// 방문 기록 관리 StateNotifier
class VisitNotifier extends StateNotifier<AsyncValue<void>> {
final VisitRepository _repository;