196 lines
5.9 KiB
Dart
196 lines
5.9 KiB
Dart
|
|
|
|
import 'package:novyronst/common/api/api_request.dart';
|
|
import 'package:novyronst/common/api/api_string.dart';
|
|
import 'package:novyronst/common/help/help_log.dart';
|
|
import 'package:novyronst/common/model/ny_category_model.dart';
|
|
import 'package:novyronst/common/model/ny_drama_model.dart';
|
|
import 'package:novyronst/common/model/ny_home_model.dart';
|
|
|
|
import '../model/ny_detail_model.dart';
|
|
|
|
class VideoRequest {
|
|
static Future<List<NyHomeModel>> getHomeData() {
|
|
return ApiRequest.get(ApiStringVideo.getHomeModules).then((value) {
|
|
if (value.isSuccess) {
|
|
List? list = value.data['data']['list'];
|
|
List<NyHomeModel> homeList = [];
|
|
if (list != null) {
|
|
homeList = list.map((e) => NyHomeModel.fromJson(e)).toList();
|
|
}
|
|
return homeList;
|
|
}
|
|
return [];
|
|
});
|
|
}
|
|
|
|
static Future<List<NyCategoryModel>> getCategoriesList() {
|
|
return ApiRequest.get(ApiStringVideo.getCategoriesList).then((value) {
|
|
// SkyLog.print('vvvvv: ${value.data}');
|
|
if (!value.isSuccess) return [];
|
|
|
|
Map<String, dynamic> data = value.data['data'];
|
|
List? list = data['list'];
|
|
|
|
List<NyCategoryModel> categoryList = [];
|
|
if (list != null) {
|
|
// id 28 不显示,删除
|
|
categoryList = list.map((e) => NyCategoryModel.fromJson(e)).toList();
|
|
categoryList.removeWhere((element) => element.name.length >= 10);
|
|
}
|
|
return categoryList;
|
|
});
|
|
}
|
|
|
|
// getRecommandsList
|
|
static Future<List<NyDramaModel>> getRecommandsList({
|
|
int page = 1,
|
|
int pageSize = 10,
|
|
}) {
|
|
Map<String, dynamic> params = _setPage(page: page, pageSize: pageSize);
|
|
return ApiRequest.get(ApiStringVideo.getRecommandsList, queryParameters: params).then((value) {
|
|
if (value.isSuccess) {
|
|
// HelpLog.print('getRecommandsList: ${value.data}');
|
|
List list = parseDataForList(value.data);
|
|
return list.map((e) => NyDramaModel.fromJson(e)).toList();
|
|
}
|
|
return [];
|
|
});
|
|
}
|
|
|
|
static Future<List<NyDramaModel>> getCategoriesDetail({
|
|
required int categoryId,
|
|
int page = 1,
|
|
int pageSize = 20,
|
|
}) {
|
|
return ApiRequest.fetchPage<NyDramaModel>(
|
|
ApiStringVideo.getCategoriesDetail,
|
|
page: page,
|
|
pageSize: pageSize,
|
|
extraParams: {'category_id': categoryId},
|
|
fromJson: (json) => NyDramaModel.fromJson(json),
|
|
);
|
|
}
|
|
|
|
// getSearchHots
|
|
static Future<List<NyDramaModel>> getSearchTrending() {
|
|
return ApiRequest.get(ApiStringVideo.getSearchHots).then((value) {
|
|
if (value.isSuccess) {
|
|
HelpLog.print('getSearchHots: ${value.data}');
|
|
List list = parseDataForList(value.data);
|
|
return list.map((e) => NyDramaModel.fromJson(e)).toList();
|
|
}
|
|
return [];
|
|
});
|
|
}
|
|
|
|
// search
|
|
static Future<List<NyDramaModel>> search({required String keyword}) {
|
|
return ApiRequest.get(ApiStringVideo.getSearch, queryParameters: {
|
|
'search': keyword,
|
|
}).then((value) {
|
|
if (value.isSuccess) {
|
|
HelpLog.print('getSearchHots: ${value.data}');
|
|
List list = parseDataForList(value.data);
|
|
return list.map((e) => NyDramaModel.fromJson(e)).toList();
|
|
}
|
|
return [];
|
|
});
|
|
}
|
|
|
|
//getCollections
|
|
static Future<List<NyDramaModel>> getCollections({
|
|
int page = 1,
|
|
int pageSize = 10,
|
|
}) {
|
|
Map<String, dynamic> params = _setPage(page: page, pageSize: pageSize);
|
|
return ApiRequest.get(
|
|
ApiStringVideo.getCollections,
|
|
queryParameters: params,
|
|
).then((value) {
|
|
if (value.isSuccess) {
|
|
HelpLog.print('getCollections: ${value.data}');
|
|
List list = parseDataForList(value.data);
|
|
return list.map((e) => NyDramaModel.fromJson(e)).toList();
|
|
}
|
|
return [];
|
|
});
|
|
}
|
|
|
|
// getHistory
|
|
static Future<List<NyDramaModel>> getHistory({
|
|
int page = 1,
|
|
int pageSize = 10,
|
|
}) {
|
|
Map<String, dynamic> params = _setPage(page: page, pageSize: pageSize);
|
|
return ApiRequest.get(
|
|
ApiStringVideo.getHistories,
|
|
queryParameters: params,
|
|
).then((value) {
|
|
if (value.isSuccess) {
|
|
HelpLog.print('getHistory: ${value.data}');
|
|
List list = parseDataForList(value.data);
|
|
return list.map((e) => NyDramaModel.fromJson(e)).toList();
|
|
}
|
|
return [];
|
|
});
|
|
}
|
|
|
|
// getVideoDetail
|
|
static Future<NyDetailModel?> getVideoDetail({
|
|
required int shortPlayId,
|
|
required int shortPlayVideoId,
|
|
}) {
|
|
Map<String, dynamic> params = {};
|
|
params['short_play_id'] = shortPlayId;
|
|
params['short_play_video_id'] = shortPlayVideoId;
|
|
return ApiRequest.get(
|
|
ApiStringVideo.getVideoDetail,
|
|
queryParameters: params,
|
|
).then((value) {
|
|
if (value.isSuccess) {
|
|
HelpLog.print('getVideoDetail: ${value.data['data']}');
|
|
return NyDetailModel.fromJson(value.data['data']);
|
|
}
|
|
return null;
|
|
});
|
|
}
|
|
|
|
// collect
|
|
static Future<bool> collect({
|
|
required int shortPlayId,
|
|
required int videoId,
|
|
}) {
|
|
Map<String, dynamic> params = {};
|
|
params['short_play_id'] = shortPlayId;
|
|
params['video_id'] = videoId;
|
|
return ApiRequest.post(ApiStringVideo.collect, data: params).then((value) {
|
|
HelpLog.print('collecttttt: ${value.data}');
|
|
if (value.isSuccess) {}
|
|
return value.isSuccess;
|
|
});
|
|
}
|
|
|
|
// cancelCollect
|
|
static Future<bool> cancelCollect({required int shortPlayId}) {
|
|
Map<String, dynamic> params = {};
|
|
params['short_play_id'] = shortPlayId;
|
|
return ApiRequest.post(ApiStringVideo.cancelCollect, data: params).then((
|
|
value,
|
|
) {
|
|
HelpLog.print('cancelCollectttt: ${value.data}');
|
|
if (value.isSuccess) {}
|
|
return value.isSuccess;
|
|
});
|
|
}
|
|
|
|
static Map<String, dynamic> _setPage({int page = 1, int pageSize = 10}) {
|
|
return {'current_page': page, 'page_size': pageSize};
|
|
}
|
|
|
|
static List parseDataForList(Map<String, dynamic> data) {
|
|
Map<String, dynamic> map = data['data'];
|
|
List? listData = map['list'];
|
|
return listData ?? [];
|
|
}
|
|
} |