PersonDynViewModel.m
3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
// PersonDynViewModel.m
// DreamSleep
//
// Created by peter on 2022/10/12.
//
#import "PersonDynViewModel.h"
#import "MyDynamicListResultModel.h"
@interface PersonDynViewModel ()
/// 我的动态列表结果数据model
@property (nonatomic, strong) MyDynamicListResultModel *resultModel;
@end
@implementation PersonDynViewModel
- (NSURLSessionDataTask *)queryUserDynamicListWithLoadMore:(BOOL)loadMore offset:(int)offset completion:(void (^)(PersonDynViewModel *requestModel))completion {
NSString *api = @"query_user_dynamic_list";
NSString *argStr = [NSString stringWithFormat:@"query{%@(offset:%d)}", api, offset];
return [PersonDynViewModel httpPostBodyRequestWithAPI:api params:@{@"query" : argStr} view:nil hasNetActivity:YES loadingInfo:nil hasFailInfo:NO success:^(NSDictionary * _Nonnull apiDic) {
DSLog(@"我的动态列表接口apiDic:%@", apiDic);
// 1、解析数据
self.resCode = DSResCodeSuccess;
self.resultModel = [MyDynamicListResultModel yy_modelWithDictionary:apiDic[@"result"]];
// 2、根据业务需要的数据结构对数据进行加工
NSArray *latest_data_list = self.resultModel.dataList ?: @[];
self.latestDataList = latest_data_list;
if (loadMore) {
NSMutableArray *tmp_list_arr = [NSMutableArray arrayWithArray:self.listArr];
[tmp_list_arr addObjectsFromArray:latest_data_list.copy];
self.listArr = tmp_list_arr.copy;
} else {
self.listArr = latest_data_list.copy;
}
// 3、给model标记类型
[self.listArr enumerateObjectsUsingBlock:^(ComDynModel * obj, NSUInteger idx, BOOL * _Nonnull stop) {
obj.modelType = DynModelTypeMyDyn;
}];
completion(self);
} failure:^(id _Nonnull failureInfo) {
self.resCode = [failureInfo[@"errorCode"] integerValue];
self.errMessage = failureInfo[@"errMessage"];
completion(self);
}];
}
- (NSURLSessionDataTask *)communityDeleteOperationWithCompletion:(void (^)(PersonDynViewModel *requestModel))completion {
NSString *api = @"community_delete_operation";
NSString *argStr = [NSString stringWithFormat:@"mutation{%@(oper_type:\"%@\",delete_id:%d)}", api, self.oper_type, self.delete_id];
return [PersonDynViewModel httpPostBodyRequestWithAPI:api params:@{@"query" : argStr} view:nil hasNetActivity:YES loadingInfo:nil hasFailInfo:NO success:^(NSDictionary * _Nonnull apiDic) {
DSLog(@"用户-删除动态,评论,回复接口apiDic:%@", apiDic);
self.resCode = DSResCodeSuccess;
completion(self);
} failure:^(id _Nonnull failureInfo) {
self.resCode = [failureInfo[@"errorCode"] integerValue];
self.errMessage = failureInfo[@"errMessage"];
completion(self);
}];
}
- (void)deleteComDynWithDynamicID:(int)dynamicID {
NSMutableArray *tmpListArr = [NSMutableArray arrayWithArray:self.listArr];
[tmpListArr enumerateObjectsUsingBlock:^(ComDynModel * obj, NSUInteger idx, BOOL * _Nonnull stop) {
if (obj.dynamicID == dynamicID) {
*stop = YES;
[tmpListArr removeObject:obj];
}
}];
self.listArr = tmpListArr.copy;
}
@end