34 lines
1.2 KiB
Dart
34 lines
1.2 KiB
Dart
import 'package:hive_flutter/hive_flutter.dart';
|
|
import 'package:lunchpick/core/constants/app_constants.dart';
|
|
import 'package:lunchpick/domain/entities/restaurant.dart';
|
|
import 'package:lunchpick/domain/entities/visit_record.dart';
|
|
|
|
import 'store_dataset_seeder.dart';
|
|
import 'manual_restaurant_samples.dart';
|
|
|
|
/// 초기 구동 시 샘플 데이터를 채워 넣는 도우미
|
|
class SampleDataInitializer {
|
|
static Future<void> seedInitialData() async {
|
|
await StoreDatasetSeeder().seedIfNeeded();
|
|
await seedManualRestaurantsIfNeeded();
|
|
}
|
|
|
|
static Future<void> seedManualRestaurantsIfNeeded() async {
|
|
final restaurantBox = Hive.box<Restaurant>(AppConstants.restaurantBox);
|
|
final visitBox = Hive.box<VisitRecord>(AppConstants.visitRecordBox);
|
|
|
|
// 이미 사용자 데이터가 있으면 샘플을 추가하지 않음
|
|
if (restaurantBox.isNotEmpty || visitBox.isNotEmpty) {
|
|
return;
|
|
}
|
|
|
|
final samples = ManualRestaurantSamples.build();
|
|
for (final sample in samples) {
|
|
await restaurantBox.put(sample.restaurant.id, sample.restaurant);
|
|
for (final visit in sample.visits) {
|
|
await visitBox.put(visit.id, visit);
|
|
}
|
|
}
|
|
}
|
|
}
|