This commit is contained in:
2025-12-11 13:40:32 +08:00
parent d348b35984
commit 45695364e9
11 changed files with 123 additions and 29 deletions

View File

@@ -7,6 +7,7 @@
#import <Foundation/Foundation.h>
#import "KBCharacter.h"
#import "KBMyTheme.h"
@class KBUser;
NS_ASSUME_NONNULL_BEGIN
@@ -22,6 +23,7 @@ typedef void(^KBUpLoadAvatarCompletion)(BOOL success, NSError * _Nullable error)
typedef void(^KBUpdateUserInfoCompletion)(BOOL success, NSError * _Nullable error);
typedef void(^KBUpdateCharacterSortCompletion)(BOOL success, NSError * _Nullable error);
typedef void(^KBDeleteUserCharacterCompletion)(BOOL success, NSError * _Nullable error);
typedef void(^KBMyPurchasedThemesCompletion)(NSArray<KBMyTheme *> *_Nullable themes, NSError *_Nullable error);
@interface KBMyVM : NSObject
@@ -30,6 +32,8 @@ typedef void(^KBDeleteUserCharacterCompletion)(BOOL success, NSError * _Nullable
/// 用户人设列表(/character/listByUser
- (void)fetchCharacterListByUserWithCompletion:(KBCharacterListCompletion)completion;
/// 已购买主题列表(/themes/purchased
- (void)fetchPurchasedThemesWithCompletion:(KBMyPurchasedThemesCompletion)completion;
/// 更新用户人设排序
- (void)updateUserCharacterSortWithSortArray:(NSArray<NSNumber *> *)sortArray
completion:(KBUpdateCharacterSortCompletion)completion;

View File

@@ -86,6 +86,34 @@ NSString * const KBUserCharacterDeletedNotification = @"KBUserCharacterDeletedNo
}];
}
- (void)fetchPurchasedThemesWithCompletion:(KBMyPurchasedThemesCompletion)completion {
[[KBNetworkManager shared] GET:API_THEME_PURCHASED
parameters:nil
headers:nil
autoShowBusinessError:NO
completion:^(NSDictionary *jsonOrData, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (error) {
NSString *msg = KBBizMessageFromJSONObject(jsonOrData) ?: error.localizedDescription ?: KBLocalized(@"Network error");
[KBHUD showInfo:msg];
if (completion) completion(nil, error);
return;
}
id dataObj = jsonOrData[KBData] ?: jsonOrData[@"data"];
if (![dataObj isKindOfClass:[NSArray class]]) {
NSError *e = [NSError errorWithDomain:KBNetworkErrorDomain
code:KBNetworkErrorInvalidResponse
userInfo:@{NSLocalizedDescriptionKey: KBLocalized(@"Invalid response")}];
[KBHUD showInfo:e.localizedDescription];
if (completion) completion(nil, e);
return;
}
NSArray<KBMyTheme *> *themes = [KBMyTheme mj_objectArrayWithKeyValuesArray:(NSArray *)dataObj];
if (completion) completion(themes, nil);
}];
}
///
- (void)updateUserCharacterSortWithSortArray:(NSArray<NSNumber *> *)sortArray
completion:(KBUpdateCharacterSortCompletion)completion {