get method

  1. @override
Future<Either<Failure, List<AppNotification>>> get({
  1. Map<String, dynamic>? params,
  2. required int skip,
})
override

Implementation

@override
Future<Either<Failure, List<AppNotification>>> get({Map<String, dynamic>? params, required int skip}) async {
  return wrapAndHandleHttpRequestResponse<List<AppNotification>>(
    () {
      final limit = notificationConfig.notificationLimit;

      final defaultQueryParams = queryMerge(
        params,
        {
          "filter": jsonEncode({
            "archivedAt": {"\$eq": null}
          }),
          "sort": "-createdAt",
          if (limit != null) "limit": limit,
        },
      );
      final url = notificationConfig.getListApiEndpoint(
        queryMerge(
          defaultQueryParams,
          params,
        ),
      );

      final response = client!.get(url);
      return response;
    },
    onResponse: (response, left, right) {
      logger.d(response.body);
      final String notificationsRaw = response.body;

      return right(
        notificationConfig.getListResponseParser?.call(response) ??
            _defaultResponseNotificationParser(
              notificationsRaw,
              notificationConfig.metadataMapper ?? _defaultMetadataMapper,
            ),
      );
    },
  );
}