DynamicViewModel.m 1.3 KB
//
//  DynamicViewModel.m
//  DreamSleep
//
//  Created by peter on 2022/9/24.
//

#import "DynamicViewModel.h"

@implementation DynamicViewModel

- (instancetype)init {
    if (self = [super init]) {
        self.selectedPhotos = [NSMutableArray array];
        self.selectedAssets = [NSMutableArray array];
        
        self.content = @"";
        self.imgs_url = @"";
    }
    return self;
}

- (NSURLSessionDataTask *)publishDynamicWithCompletion:(void (^)(DynamicViewModel *viewModel))completion {
    NSString *api = @"publish_dynamic_data";
    NSString *argStr = [NSString stringWithFormat:@"mutation{%@(content:\"%@\",imgs_url:\"%@\")}", api, self.content, self.imgs_url];
    return [DynamicViewModel httpPostBodyRequestWithAPI:api params:@{@"query" : argStr} view:nil hasNetActivity:YES loadingInfo:nil hasFailInfo:NO success:^(NSDictionary * _Nonnull apiDic) {
        DSLog(@"用户发布动态接口apiDic:%@", apiDic);
        NSDictionary *resultDic = apiDic[@"result"];
        self.myDynModel = [ComDynModel yy_modelWithDictionary:resultDic];
        self.resCode = DSResCodeSuccess;
        completion(self);
    } failure:^(id _Nonnull failureInfo) {
        self.resCode = [failureInfo[@"errorCode"] integerValue];
        self.errMessage = failureInfo[@"errMessage"];
        completion(self);
    }];
}

@end