feat(app): add manual entry and sharing flows

This commit is contained in:
JiWoong Sul
2025-11-19 16:36:39 +09:00
parent 5ade584370
commit 947fe59486
110 changed files with 5937 additions and 3781 deletions

View File

@@ -4,26 +4,32 @@ import 'package:lunchpick/domain/repositories/recommendation_repository.dart';
class RecommendationRepositoryImpl implements RecommendationRepository {
static const String _boxName = 'recommendations';
Future<Box<RecommendationRecord>> get _box async =>
Future<Box<RecommendationRecord>> get _box async =>
await Hive.openBox<RecommendationRecord>(_boxName);
@override
Future<List<RecommendationRecord>> getAllRecommendationRecords() async {
final box = await _box;
final records = box.values.toList();
records.sort((a, b) => b.recommendationDate.compareTo(a.recommendationDate));
records.sort(
(a, b) => b.recommendationDate.compareTo(a.recommendationDate),
);
return records;
}
@override
Future<List<RecommendationRecord>> getRecommendationsByRestaurantId(String restaurantId) async {
Future<List<RecommendationRecord>> getRecommendationsByRestaurantId(
String restaurantId,
) async {
final records = await getAllRecommendationRecords();
return records.where((r) => r.restaurantId == restaurantId).toList();
}
@override
Future<List<RecommendationRecord>> getRecommendationsByDate(DateTime date) async {
Future<List<RecommendationRecord>> getRecommendationsByDate(
DateTime date,
) async {
final records = await getAllRecommendationRecords();
return records.where((record) {
return record.recommendationDate.year == date.year &&
@@ -39,8 +45,12 @@ class RecommendationRepositoryImpl implements RecommendationRepository {
}) async {
final records = await getAllRecommendationRecords();
return records.where((record) {
return record.recommendationDate.isAfter(startDate.subtract(const Duration(days: 1))) &&
record.recommendationDate.isBefore(endDate.add(const Duration(days: 1)));
return record.recommendationDate.isAfter(
startDate.subtract(const Duration(days: 1)),
) &&
record.recommendationDate.isBefore(
endDate.add(const Duration(days: 1)),
);
}).toList();
}
@@ -93,14 +103,19 @@ class RecommendationRepositoryImpl implements RecommendationRepository {
} catch (_) {
yield <RecommendationRecord>[];
}
yield* box.watch().asyncMap((_) async => await getAllRecommendationRecords());
yield* box.watch().asyncMap(
(_) async => await getAllRecommendationRecords(),
);
}
@override
Future<Map<String, int>> getMonthlyRecommendationStats(int year, int month) async {
Future<Map<String, int>> getMonthlyRecommendationStats(
int year,
int month,
) async {
final startDate = DateTime(year, month, 1);
final endDate = DateTime(year, month + 1, 0); // 해당 월의 마지막 날
final records = await getRecommendationsByDateRange(
startDate: startDate,
endDate: endDate,
@@ -111,7 +126,7 @@ class RecommendationRepositoryImpl implements RecommendationRepository {
final dayKey = record.recommendationDate.day.toString();
stats[dayKey] = (stats[dayKey] ?? 0) + 1;
}
return stats;
}
}
}