fix(calendar): 월별 방문 카테고리 집계 반영
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user