1
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#import "AiVM.h"
|
||||
#import "KBAPI.h"
|
||||
#import "KBNetworkManager.h"
|
||||
#import "KBCommentModel.h"
|
||||
#import <MJExtension/MJExtension.h>
|
||||
|
||||
@implementation KBAiSyncData
|
||||
@@ -426,4 +427,176 @@ autoShowBusinessError:NO
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - 评论相关接口
|
||||
|
||||
- (void)addCommentWithCompanionId:(NSInteger)companionId
|
||||
content:(NSString *)content
|
||||
parentId:(nullable NSNumber *)parentId
|
||||
rootId:(NSInteger)rootId
|
||||
completion:(void (^)(NSInteger, NSError * _Nullable))completion {
|
||||
if (content.length == 0) {
|
||||
NSError *error = [NSError errorWithDomain:@"AiVM"
|
||||
code:-1
|
||||
userInfo:@{NSLocalizedDescriptionKey: @"评论内容不能为空"}];
|
||||
if (completion) {
|
||||
completion(-1, error);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
NSMutableDictionary *params = [NSMutableDictionary dictionary];
|
||||
params[@"companionId"] = @(companionId);
|
||||
params[@"content"] = content;
|
||||
params[@"rootId"] = @(rootId);
|
||||
if (parentId) {
|
||||
params[@"parentId"] = parentId;
|
||||
}
|
||||
|
||||
NSLog(@"[AiVM] /ai-companion/comment/add request: %@", params);
|
||||
[[KBNetworkManager shared]
|
||||
POST:@"/ai-companion/comment/add"
|
||||
jsonBody:[params copy]
|
||||
headers:nil
|
||||
autoShowBusinessError:NO
|
||||
completion:^(NSDictionary *_Nullable json,
|
||||
NSURLResponse *_Nullable response,
|
||||
NSError *_Nullable error) {
|
||||
if (error) {
|
||||
NSLog(@"[AiVM] /ai-companion/comment/add failed: %@", error.localizedDescription ?: @"");
|
||||
if (completion) {
|
||||
completion(-1, error);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
NSLog(@"[AiVM] /ai-companion/comment/add response: %@", json);
|
||||
NSInteger code = [json[@"code"] integerValue];
|
||||
if (completion) {
|
||||
completion(code, nil);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)fetchCommentsWithCompanionId:(NSInteger)companionId
|
||||
pageNum:(NSInteger)pageNum
|
||||
pageSize:(NSInteger)pageSize
|
||||
completion:(void (^)(KBCommentPageModel * _Nullable, NSError * _Nullable))completion {
|
||||
NSDictionary *params = @{
|
||||
@"companionId": @(companionId),
|
||||
@"pageNum": @(pageNum > 0 ? pageNum : 1),
|
||||
@"pageSize": @(pageSize > 0 ? pageSize : 20)
|
||||
};
|
||||
|
||||
NSLog(@"[AiVM] /ai-companion/comment/page request: %@", params);
|
||||
[[KBNetworkManager shared]
|
||||
POST:@"/ai-companion/comment/page"
|
||||
jsonBody:params
|
||||
headers:nil
|
||||
autoShowBusinessError:NO
|
||||
completion:^(NSDictionary *_Nullable json,
|
||||
NSURLResponse *_Nullable response,
|
||||
NSError *_Nullable error) {
|
||||
if (error) {
|
||||
NSLog(@"[AiVM] /ai-companion/comment/page failed: %@", error.localizedDescription ?: @"");
|
||||
if (completion) {
|
||||
completion(nil, error);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
NSLog(@"[AiVM] /ai-companion/comment/page response: %@", json);
|
||||
|
||||
NSInteger code = [json[@"code"] integerValue];
|
||||
if (code != 0) {
|
||||
NSString *message = json[@"message"] ?: @"请求失败";
|
||||
NSError *bizError = [NSError errorWithDomain:@"AiVM"
|
||||
code:code
|
||||
userInfo:@{NSLocalizedDescriptionKey: message}];
|
||||
if (completion) {
|
||||
completion(nil, bizError);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
id dataObj = json[@"data"];
|
||||
if ([dataObj isKindOfClass:[NSDictionary class]]) {
|
||||
KBCommentPageModel *pageModel = [KBCommentPageModel mj_objectWithKeyValues:dataObj];
|
||||
if (completion) {
|
||||
completion(pageModel, nil);
|
||||
}
|
||||
} else {
|
||||
NSError *parseError = [NSError errorWithDomain:@"AiVM"
|
||||
code:-1
|
||||
userInfo:@{NSLocalizedDescriptionKey: @"数据格式错误"}];
|
||||
if (completion) {
|
||||
completion(nil, parseError);
|
||||
}
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)likeCommentWithCommentId:(NSInteger)commentId
|
||||
completion:(void (^)(KBCommentLikeResponse * _Nullable, NSError * _Nullable))completion {
|
||||
NSDictionary *params = @{
|
||||
@"commentId": @(commentId)
|
||||
};
|
||||
|
||||
NSLog(@"[AiVM] /ai-companion/comment/like request: %@", params);
|
||||
[[KBNetworkManager shared]
|
||||
POST:@"/ai-companion/comment/like"
|
||||
jsonBody:params
|
||||
headers:nil
|
||||
autoShowBusinessError:NO
|
||||
completion:^(NSDictionary *_Nullable json,
|
||||
NSURLResponse *_Nullable response,
|
||||
NSError *_Nullable error) {
|
||||
if (error) {
|
||||
NSLog(@"[AiVM] /ai-companion/comment/like failed: %@", error.localizedDescription ?: @"");
|
||||
if (completion) {
|
||||
completion(nil, error);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
NSLog(@"[AiVM] /ai-companion/comment/like response: %@", json);
|
||||
|
||||
KBCommentLikeResponse *likeResponse = [KBCommentLikeResponse mj_objectWithKeyValues:json];
|
||||
if (completion) {
|
||||
completion(likeResponse, nil);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)likeCompanionWithCompanionId:(NSInteger)companionId
|
||||
completion:(void (^)(KBCommentLikeResponse * _Nullable, NSError * _Nullable))completion {
|
||||
NSDictionary *params = @{
|
||||
@"companionId": @(companionId)
|
||||
};
|
||||
|
||||
NSLog(@"[AiVM] /ai-companion/like request: %@", params);
|
||||
[[KBNetworkManager shared]
|
||||
POST:@"/ai-companion/like"
|
||||
jsonBody:params
|
||||
headers:nil
|
||||
autoShowBusinessError:NO
|
||||
completion:^(NSDictionary *_Nullable json,
|
||||
NSURLResponse *_Nullable response,
|
||||
NSError *_Nullable error) {
|
||||
if (error) {
|
||||
NSLog(@"[AiVM] /ai-companion/like failed: %@", error.localizedDescription ?: @"");
|
||||
if (completion) {
|
||||
completion(nil, error);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
NSLog(@"[AiVM] /ai-companion/like response: %@", json);
|
||||
|
||||
KBCommentLikeResponse *likeResponse = [KBCommentLikeResponse mj_objectWithKeyValues:json];
|
||||
if (completion) {
|
||||
completion(likeResponse, nil);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user