Files
eatvio_app/lib/features/plans/repositories/plan_repository.dart
alex-chevski 0df474b2b5 fix: plans - like and bookmark in consultant profile (#582)
- decouple PlanWidget from feed PlansCubit via owner-provided callbacks
- add like/favorite actions to profile PlansCubit: slug lookup, optimistic
  update, rollback of the affected plan, per-slug debounce, isClosed guards
- pass slug through like/favorite/comments events; guard out-of-range index
  in feed plans handlers and deep-link about_plan sync
- capture post like intent before await in profile blog post widget
- replace null force-unwraps in profile screen, guard indexOf == -1
- tests: profile plan like/bookmark, slug sync, bounds guards, #700 regression
2026-11-20 16:30:13 +03:00

48 lines
1.8 KiB
Dart

import 'dart:async';
import 'package:eatvio_app/features/diets/repositories/diet_repository.dart';
import 'package:eatvio_app/features/feed/models/plan_pagination_model.dart';
import 'package:eatvio_app/features/plans/models/chosen_plan_model.dart';
import 'package:eatvio_app/features/plans/services/plan_service.dart';
class PlanRepository {
final PlanService planService;
PlanRepository({required this.planService});
final _planLikeStateStreamController = StreamController<LikesState>.broadcast();
final _planFavoriteStateStreamController = StreamController<FavoriteState>.broadcast();
final _planCommentsStateStreamController = StreamController<CommentsState>.broadcast();
Stream<LikesState> get planLikeState => _planLikeStateStreamController.stream;
Stream<FavoriteState> get planFavoriteState => _planFavoriteStateStreamController.stream;
Stream<CommentsState> get planCommentsState => _planCommentsStateStreamController.stream;
Future<PlanModel> getPlan(String slug) async {
return planService.getPlan(slug);
}
Future<void> likePlan(String slug) async {
await planService.likePlan(slug: slug);
}
Future<void> addToFavorite(String slug) async {
await planService.addToFavorite(slug: slug);
}
Future<void> removeFromFavorite(String slug) async {
await planService.removeFromFavorite(slug: slug);
}
Future<ChosenPlanModel> chosePlan(String slug, Map<String, dynamic> option ) async {
return await planService.chosePlan(slug: slug, option: option);
}
void emitLikesStateToFeed(LikesState state) => _planLikeStateStreamController.add(state);
void emitFavoriteStateToFeed(FavoriteState state) => _planFavoriteStateStreamController.add(state);
void emitCommentsStateToFeed(CommentsState state) => _planCommentsStateStreamController.add(state);
}