glp-companion/lib/features/nutrition/domain/repositories/nutrition_repository.dart

57 lines
2.2 KiB
Dart

import '../entities/food_log_entry.dart';
import '../entities/hydration_log_entry.dart';
/// Persistence contract for the nutrition bounded context.
///
/// The presentation layer depends only on this interface; the drift-backed
/// implementation lives in `data/repositories/` so widgets and controllers
/// remain testable with in-memory fakes.
abstract class INutritionRepository {
// ---------------------------------------------------------------------------
// Food diary
// ---------------------------------------------------------------------------
/// Emits the food diary (newest first) whenever it changes.
Stream<List<FoodLogEntry>> watchFoodLogs({int limit = 500});
/// One-shot snapshot of the food diary (newest first).
///
/// When [from]/[to] are provided only entries with `from <= timestamp < to`
/// are returned, which the controller uses to build the "today" view.
Future<List<FoodLogEntry>> getFoodLogs({
int limit = 500,
DateTime? from,
DateTime? to,
});
/// Persists [entry]; when [FoodLogEntry.id] is `null` a new row is inserted,
/// otherwise the existing row is updated. Returns the stored entry with its
/// database-assigned identifier.
Future<FoodLogEntry> saveFoodLog(FoodLogEntry entry);
/// Removes the food entry with [id], if present.
Future<void> deleteFoodLog(int id);
// ---------------------------------------------------------------------------
// Hydration
// ---------------------------------------------------------------------------
/// Emits the hydration log (newest first) whenever it changes.
Stream<List<HydrationLogEntry>> watchHydrationLogs({int limit = 500});
/// One-shot snapshot of the hydration log (newest first), optionally
/// filtered by the half-open interval `[from, to)`.
Future<List<HydrationLogEntry>> getHydrationLogs({
int limit = 500,
DateTime? from,
DateTime? to,
});
/// Persists [entry]; when [HydrationLogEntry.id] is `null` a new row is
/// inserted, otherwise the existing row is updated. Returns the stored entry
/// with its database-assigned identifier.
Future<HydrationLogEntry> saveHydrationLog(HydrationLogEntry entry);
/// Removes the hydration entry with [id], if present.
Future<void> deleteHydrationLog(int id);
}