27 lines
951 B
Dart
27 lines
951 B
Dart
import 'package:proxibuy/data/models/datasources/offer_data_source.dart';
|
|
import 'package:proxibuy/data/models/offer_model.dart';
|
|
|
|
class OfferRepository {
|
|
final OfferDataSource _offerDataSource;
|
|
|
|
OfferRepository({required OfferDataSource offerDataSource})
|
|
: _offerDataSource = offerDataSource;
|
|
|
|
Future<List<OfferModel>> fetchOffers({required List<String> selectedCategories}) async {
|
|
final allOffers = await _offerDataSource.getNearbyOffers();
|
|
|
|
if (selectedCategories.isEmpty) {
|
|
return allOffers;
|
|
}
|
|
|
|
final filteredOffers = allOffers
|
|
.where((offer) => selectedCategories.contains(offer.category))
|
|
.toList();
|
|
|
|
return filteredOffers;
|
|
}
|
|
Future<OfferModel?> fetchOfferById(String id) async {
|
|
// در آینده این متد میتواند یک درخواست API برای گرفتن اطلاعات یک محصول خاص ارسال کند
|
|
return _offerDataSource.getOfferById(id);
|
|
}
|
|
} |