getFilters method

Future<ApiCallback<FiltersResponse>> getFilters(
  1. {String categoryId,
  2. bool perSeller = false,
  3. String term,
  4. String tag}
)

Implementation

Future<ApiCallback<FiltersResponse>> getFilters({
  String categoryId,
  bool perSeller = false,
  String term,
  String tag,
}) async {
  try {
    Map<String, dynamic> queryParameters = {};

    if (perSeller) {
      var cart = await CartDao().get();
      if (cart.seller != null) {
        queryParameters["sellerId"] = cart.seller.id;
      }
    }

    if (categoryId != null) {
      queryParameters["categoryId"] = categoryId;
    }

    if (term != null && term.isNotEmpty) {
      queryParameters["query"] = term;
    }

    if (tag != null && tag.isNotEmpty) {
      queryParameters["tag"] = tag;
    }

    var response = await _requester.get(
      await _catalogEndpoint(API_PRODUCTS_FILTERS, includeSeller: false),
      options: Options(responseType: ResponseType.json),
      queryParameters: queryParameters,
    );
    FiltersResponse filtersModel = FiltersResponse.fromJson(response.data);
    return ApiCallback<FiltersResponse>(isSuccessful: true, resultData: filtersModel);
  } on DioError catch (e) {
    return ApiCallback<FiltersResponse>().defaultErrorCallback(e);
  } catch (e) {
    return ApiCallback(isSuccessful: false, error: null, resultErrorMessage: e.toString());
  }
}