You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.2 KiB

//
// Photo.m
// watch
//
// Created by xTT on 2017/7/22.
// Copyright © 2017xTT. All rights reserved.
//
#import "Photo.h"
#import "User.h"
@implementation Photo
+ (void)getObjsWithID:(NSString *)ID
success:(void (^)(NSMutableArray *arr))success
failure:(void (^)(NSError *error))failure{
NSString *urlStr = [MyHttp getURL:@"[vendor]/devices/[imei]/photograph"
objArr:@[cUser.cDevice]];
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
if (ID) {
NSDictionary *tmp = @{@"id":@{@"lt":ID}};
[parameters setObject:tmp.mj_JSONString forKey:@"query"];
[parameters setObject:@"id" forKey:@"sortKey"];
}
[xMyHttp URL:urlStr
method:@"GET" parameters:parameters
success:^(NSURLSessionDataTask *task, id responseObject)
{
if ([responseObject[@"code"] intValue] == HTTP_SUCCESS) {
NSMutableArray *arr = [Photo mj_objectArrayWithKeyValuesArray:responseObject[@"photos"]];
success(arr);
}
} failure:^(NSURLSessionDataTask *task, NSError *error) {
if (failure) {
failure(error);
}
}];
}
+ (void)deletePhotos:(NSMutableArray *)photoArr
success:(void (^)())success
failure:(void (^)())failure{
NSString *urlStr = [MyHttp getURL:@"[vendor]/devices/[imei]/photograph"
objArr:@[cUser.cDevice]];
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
NSMutableArray *ids = [NSMutableArray array];
[photoArr enumerateObjectsUsingBlock:^(Photo *obj, NSUInteger idx, BOOL * _Nonnull stop) {
[ids addObject:obj.id];
}];
[parameters setValue:[ids mj_JSONString] forKey:@"ids"];
[xMyHttp URL:urlStr
method:@"DELETE" parameters:parameters
success:^(NSURLSessionDataTask *task, id responseObject)
{
if ([responseObject[@"code"] intValue] == HTTP_SUCCESS) {
success();
}else{
failure();
}
} failure:^(NSURLSessionDataTask *task, NSError *error) {
if (failure) {
failure();
}
}];
}
@end