@@ -6,22 +6,59 @@ import 'package:wooapp/model/product.dart';
66import 'package:wooapp/screens/featured/featured_sort.dart' ;
77
88class CatalogDataSourceImpl extends CatalogDataSource {
9-
109 final WooApiClient _api = locator <WooApiClient >();
1110
1211 @override
13- Future <List <Category >> getCategories (int page, Sort sort) => _api.dio
14- .get ('products/categories?hide_empty=true&parent=0&per_page=${WooAppConfig .paginationLimit }&page=$page &$sort ' )
15- .then ((response) => (response.data as List ).map ((item) => Category .fromJson (item)).toList ());
12+ Future <List <Category >> getCategories (
13+ int page,
14+ Sort sort,
15+ ) =>
16+ _api.dio
17+ .get (
18+ 'products/categories?hide_empty=true'
19+ '&parent=0'
20+ '&per_page=${WooAppConfig .paginationLimit }'
21+ '&page=$page &$sort ' ,
22+ )
23+ .then (
24+ (response) => (response.data as List )
25+ .map ((item) => Category .fromJson (item))
26+ .toList (),
27+ );
1628
1729 @override
18- Future <List <Product >> getCatalogProducts (int category) => _api.dio
19- .get ('products?status=publish&per_page=10&page=1&category=$category ' )
20- .then ((response) => (response.data as List ).map ((item) => Product .fromJson (item)).toList ());
30+ Future <List <Product >> getCatalogProducts (
31+ int category, {
32+ List <int > excludedProductIds = const [],
33+ }) =>
34+ _api.dio
35+ .get (
36+ 'products?status=publish'
37+ '&per_page=10'
38+ '&page=1'
39+ '${_mapExcludedParam (excludedProductIds )}'
40+ '&category=$category ' ,
41+ )
42+ .then (
43+ (response) => (response.data as List )
44+ .map ((item) => Product .fromJson (item))
45+ .toList (),
46+ );
47+
48+ String _mapExcludedParam (List <int > excludedProductIds) {
49+ if (excludedProductIds.isEmpty) return '' ;
50+ var param = '&exclude=' ;
51+ for (var id in excludedProductIds) param += '$id ,' ;
52+ param.trim ();
53+ return param;
54+ }
2155}
2256
2357abstract class CatalogDataSource {
2458 Future <List <Category >> getCategories (int page, Sort sort);
2559
26- Future <List <Product >> getCatalogProducts (int category);
60+ Future <List <Product >> getCatalogProducts (
61+ int category, {
62+ List <int > excludedProductIds,
63+ });
2764}
0 commit comments