Skip to content

Commit 6da14e7

Browse files
committed
feat: added where method to fetch assets
1 parent e9bc305 commit 6da14e7

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

Contentstack/AssetLibrary.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,24 @@ typedef NS_ENUM(NSUInteger, OrderBy) {
230230
*/
231231

232232
- (void)fetchAll:(void (^) (ResponseType type,NSArray<Asset *> * BUILT_NULLABLE_P result,NSError * BUILT_NULLABLE_P error))completionBlock;
233+
234+
/**
235+
This method fetches assets using other fields than UID..
236+
237+
//Obj-C
238+
[assetLib where:(NSString *)field equalTo:(NSObject *)value];
239+
240+
//Swift
241+
assetLib.where("fieldName","value");
242+
243+
This allows filtering assets by specifying the field name and the value to match.
244+
@param field The name of the field to filter by.
245+
@param value The value that the field should match.
246+
*/
247+
- (void)where:(NSString *)field equalTo:(NSObject *)value ;
248+
249+
- (NSDictionary*)getPostParamDictionary;
250+
233251
@end
234252

235253
BUILT_ASSUME_NONNULL_END

Contentstack/AssetLibrary.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,25 @@ - (void)cancelRequest {
156156
[self.requestOperation cancel];
157157
}
158158
}
159+
// MARK: - Where Query -
160+
- (NSDictionary*) getPostParamDictionary {
161+
return [self.postParamDictionary copy];
162+
}
163+
164+
- (void)where:(NSString *)field equalTo:(NSObject *)value {
165+
if (field.length == 0 || !value) {
166+
NSLog(@"Field or value cannot be empty");
167+
return;
168+
}
169+
NSMutableDictionary *queryDict = [NSMutableDictionary dictionary];
170+
NSDictionary *existingQuery = self.postParamDictionary[@"query"];
171+
// If an existing query exists, merge it
172+
if (existingQuery) {
173+
[queryDict addEntriesFromDictionary:existingQuery];
174+
}
175+
queryDict[field] = value;
176+
[self.postParamDictionary setObject:queryDict forKey:@"query"];
177+
}
159178

160179

161180
@end

0 commit comments

Comments
 (0)