jacksonjude / cloudkit_flutter

CloudKit support for Flutter via CloudKit Web Services.
https://pub.dev/packages/cloudkit_flutter
BSD 3-Clause "New" or "Revised" License
9 stars 4 forks source link

Bad syntax for JSON filter when NOT systemField #3

Closed 1278real closed 2 years ago

1278real commented 2 years ago

Hi, I received a 400 Bad Request error when trying to use filter with current parsing. I fixed this in ck_filter.dart in class CKFilter :

class CKFilter {
  final CKComparator _comparator;
  final String _fieldName;
  final Map<String, dynamic> _fieldValueDictionary;
  final double? _distance;

  ///// THIS PART IS A FIX FOR NON-SYSTEMFIELD FILTERS

  dynamic _fieldValue;

  CKFilter(this._fieldName, CKFieldType fieldType, dynamic fieldValue,
      this._comparator,
      {double? distance})
      : _fieldValue = (fieldValue != null)
            ? {'value': fieldValue, 'type': fieldType.record}
            : ((fieldType is num) ? 0 : ""),
        _fieldValueDictionary = {
          'value': {_fieldName: fieldValue},
          'type': fieldType.record
        },
        _distance = distance;

  /// Convert the filter to JSON.
  Map<String, dynamic> toJSON() => {
        'comparator': _comparator._comparatorString,
        (CKConstants.isSystemFieldName(_fieldName)
            ? 'systemFieldName'
            : 'fieldName'): _fieldName,
        'fieldValue': (CKConstants.isSystemFieldName(_fieldName)
            ? _fieldValueDictionary
            : _fieldValue),
        'distance': _distance
      };

  ///// END OF FIX
}
yz commented 2 years ago

this fixed the CKFilter issue.

jacksonjude commented 2 years ago

Fixed via #5