Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Firestore/Source/API/FIRFieldValue+Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,16 @@ NS_ASSUME_NONNULL_BEGIN
@property(strong, nonatomic, readonly) NSNumber *operand;
@end

/** FIRFieldValue class for number minimum transforms. */
@interface FSTNumericMinimumFieldValue : FIRFieldValue
- (instancetype)init NS_UNAVAILABLE;
@property(strong, nonatomic, readonly) NSNumber *operand;
@end

/** FIRFieldValue class for number maximum transforms. */
@interface FSTNumericMaximumFieldValue : FIRFieldValue
- (instancetype)init NS_UNAVAILABLE;
@property(strong, nonatomic, readonly) NSNumber *operand;
@end

NS_ASSUME_NONNULL_END
58 changes: 58 additions & 0 deletions Firestore/Source/API/FIRFieldValue.mm
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,48 @@ - (NSString *)methodName {

@end

#pragma mark - FSTNumericMinimumFieldValue

/* FieldValue class for minimum() transforms. */
@interface FSTNumericMinimumFieldValue ()
- (instancetype)initWithOperand:(NSNumber *)operand;
@end

@implementation FSTNumericMinimumFieldValue
- (instancetype)initWithOperand:(NSNumber *)operand {
if (self = [super initPrivate]) {
_operand = operand;
}
return self;
}

- (NSString *)methodName {
return @"FieldValue.minimum()";
}

@end

#pragma mark - FSTNumericMaximumFieldValue

/* FieldValue class for maximum() transforms. */
@interface FSTNumericMaximumFieldValue ()
- (instancetype)initWithOperand:(NSNumber *)operand;
@end

@implementation FSTNumericMaximumFieldValue
- (instancetype)initWithOperand:(NSNumber *)operand {
if (self = [super initPrivate]) {
_operand = operand;
}
return self;
}

- (NSString *)methodName {
return @"FieldValue.maximum()";
}

@end

#pragma mark - FIRFieldValue

@implementation FIRFieldValue
Expand Down Expand Up @@ -177,6 +219,22 @@ + (instancetype)fieldValueForIntegerIncrement:(int64_t)l {
return [[FSTNumericIncrementFieldValue alloc] initWithOperand:@(l)];
}

+ (instancetype)fieldValueForDoubleMinimum:(double)d {
return [[FSTNumericMinimumFieldValue alloc] initWithOperand:@(d)];
}

+ (instancetype)fieldValueForIntegerMinimum:(int64_t)l {
return [[FSTNumericMinimumFieldValue alloc] initWithOperand:@(l)];
}

+ (instancetype)fieldValueForDoubleMaximum:(double)d {
return [[FSTNumericMaximumFieldValue alloc] initWithOperand:@(d)];
}

+ (instancetype)fieldValueForIntegerMaximum:(int64_t)l {
return [[FSTNumericMaximumFieldValue alloc] initWithOperand:@(l)];
}

+ (nonnull FIRVectorValue *)vectorWithArray:(nonnull NSArray<NSNumber *> *)array {
return [[FIRVectorValue alloc] initWithArray:array];
}
Expand Down
16 changes: 16 additions & 0 deletions Firestore/Source/API/FSTUserDataReader.mm
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@
using firebase::firestore::model::FieldTransform;
using firebase::firestore::model::NullValue;
using firebase::firestore::model::NumericIncrementTransform;
using firebase::firestore::model::NumericMaximumTransform;
using firebase::firestore::model::NumericMinimumTransform;
using firebase::firestore::model::ObjectValue;
using firebase::firestore::model::ResourcePath;
using firebase::firestore::model::ServerTimestampTransform;
Expand Down Expand Up @@ -453,6 +455,20 @@ - (void)parseSentinelFieldValue:(FIRFieldValue *)fieldValue context:(ParseContex

context.AddToFieldTransforms(*context.path(), std::move(numeric_increment));

} else if ([fieldValue isKindOfClass:[FSTNumericMinimumFieldValue class]]) {
auto *numericMinimumFieldValue = (FSTNumericMinimumFieldValue *)fieldValue;
auto operand = [self parsedQueryValue:numericMinimumFieldValue.operand];
NumericMinimumTransform numeric_minimum(std::move(operand));

context.AddToFieldTransforms(*context.path(), std::move(numeric_minimum));

} else if ([fieldValue isKindOfClass:[FSTNumericMaximumFieldValue class]]) {
auto *numericMaximumFieldValue = (FSTNumericMaximumFieldValue *)fieldValue;
auto operand = [self parsedQueryValue:numericMaximumFieldValue.operand];
NumericMaximumTransform numeric_maximum(std::move(operand));

context.AddToFieldTransforms(*context.path(), std::move(numeric_maximum));

} else {
HARD_FAIL("Unknown FIRFieldValue type: %s", NSStringFromClass([fieldValue class]));
}
Expand Down
48 changes: 48 additions & 0 deletions Firestore/Source/Public/FirebaseFirestore/FIRFieldValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,54 @@ NS_SWIFT_NAME(FieldValue)
*/
+ (instancetype)fieldValueForIntegerIncrement:(int64_t)l NS_SWIFT_NAME(increment(_:));

/**
* Returns a special value that can be used with `setData()` or `updateData()` that tells the server
* to set the field to the minimum of its current value and the given value.
*
* If the current field value is not an integer or double, or if the field does not yet exist,
* the transformation will set the field to the given value.
*
* @param d The double value to compare.
* @return The `FieldValue` sentinel for use in a call to `setData()` or `updateData()`.
*/
+ (instancetype)fieldValueForDoubleMinimum:(double)d NS_SWIFT_NAME(minimum(_:));

/**
* Returns a special value that can be used with `setData()` or `updateData()` that tells the server
* to set the field to the minimum of its current value and the given value.
*
* If the current field value is not an integer or double, or if the field does not yet exist,
* the transformation will set the field to the given value.
*
* @param l The integer value to compare.
* @return The `FieldValue` sentinel for use in a call to `setData()` or `updateData()`.
*/
+ (instancetype)fieldValueForIntegerMinimum:(int64_t)l NS_SWIFT_NAME(minimum(_:));

/**
* Returns a special value that can be used with `setData()` or `updateData()` that tells the server
* to set the field to the maximum of its current value and the given value.
*
* If the current field value is not an integer or double, or if the field does not yet exist,
* the transformation will set the field to the given value.
*
* @param d The double value to compare.
* @return The `FieldValue` sentinel for use in a call to `setData()` or `updateData()`.
*/
+ (instancetype)fieldValueForDoubleMaximum:(double)d NS_SWIFT_NAME(maximum(_:));

/**
* Returns a special value that can be used with `setData()` or `updateData()` that tells the server
* to set the field to the maximum of its current value and the given value.
*
* If the current field value is not an integer or double, or if the field does not yet exist,
* the transformation will set the field to the given value.
*
* @param l The integer value to compare.
* @return The `FieldValue` sentinel for use in a call to `setData()` or `updateData()`.
*/
+ (instancetype)fieldValueForIntegerMaximum:(int64_t)l NS_SWIFT_NAME(maximum(_:));

/**
* Creates a new `VectorValue` constructed with a copy of the given array of NSNumbers.
*
Expand Down
Loading
Loading