refactor: Update DidvanVoice fetching logic
This commit is contained in:
parent
8bd9e45bf7
commit
a805689c53
|
|
@ -325,7 +325,6 @@ class _ExploreLatestSlider extends StatelessWidget {
|
||||||
if (list.contents.isNotEmpty) {
|
if (list.contents.isNotEmpty) {
|
||||||
final newestContent = list.contents.first;
|
final newestContent = list.contents.first;
|
||||||
|
|
||||||
// Debug for monthly items
|
|
||||||
if (list.type == 'monthly') {
|
if (list.type == 'monthly') {
|
||||||
debugPrint(
|
debugPrint(
|
||||||
'🔍 MONTHLY in carousel - ID: ${newestContent.id}, File: ${newestContent.file}, Link: ${newestContent.link}');
|
'🔍 MONTHLY in carousel - ID: ${newestContent.id}, File: ${newestContent.file}, Link: ${newestContent.link}');
|
||||||
|
|
@ -402,7 +401,6 @@ class _IndustryPulseSection extends StatelessWidget {
|
||||||
placeholder: const SizedBox.shrink(),
|
placeholder: const SizedBox.shrink(),
|
||||||
onRetry: () => context.read<NewStatisticState>().init(),
|
onRetry: () => context.read<NewStatisticState>().init(),
|
||||||
builder: (context, statState) {
|
builder: (context, statState) {
|
||||||
// همهی آیتمها را از همه گروهها جمع میکنیم.
|
|
||||||
final items = <stat.Content>[];
|
final items = <stat.Content>[];
|
||||||
for (final cat in statState.contents) {
|
for (final cat in statState.contents) {
|
||||||
items.addAll(cat.contents);
|
items.addAll(cat.contents);
|
||||||
|
|
|
||||||
|
|
@ -103,11 +103,11 @@ class MainPageState extends CoreProvier {
|
||||||
_fetchStories(),
|
_fetchStories(),
|
||||||
_getSwotItems(),
|
_getSwotItems(),
|
||||||
_getDidvanPlus(),
|
_getDidvanPlus(),
|
||||||
|
_getDidvanVoice(),
|
||||||
];
|
];
|
||||||
if (AuthConfig.useLegacyApi) {
|
if (AuthConfig.useLegacyApi) {
|
||||||
tasks.addAll([
|
tasks.addAll([
|
||||||
_getMainPageContent(),
|
_getMainPageContent(),
|
||||||
_getDidvanVoice(),
|
|
||||||
_getTopBanner(),
|
_getTopBanner(),
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -485,12 +485,10 @@ class MainPageState extends CoreProvier {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// شناسهی دستهی «دیدوان پلاس» در content-service.
|
|
||||||
static const String _didvanPlusCategoryId =
|
static const String _didvanPlusCategoryId =
|
||||||
'e4c8a3b1-9d27-4e6f-bf3d-2a1c8e5f4d12';
|
'e4c8a3b1-9d27-4e6f-bf3d-2a1c8e5f4d12';
|
||||||
|
|
||||||
Future<void> _getDidvanPlus() async {
|
Future<void> _getDidvanPlus() async {
|
||||||
// مسیر جدید: content-service.
|
|
||||||
if (!AuthConfig.useLegacyApi) {
|
if (!AuthConfig.useLegacyApi) {
|
||||||
try {
|
try {
|
||||||
final res = await ContentService.instance.getContents(
|
final res = await ContentService.instance.getContents(
|
||||||
|
|
@ -501,8 +499,6 @@ class MainPageState extends CoreProvier {
|
||||||
sortBy: const [MapEntry('createdAt', 'DESC')],
|
sortBy: const [MapEntry('createdAt', 'DESC')],
|
||||||
);
|
);
|
||||||
if (!res.isSuccess || res.data == null) return;
|
if (!res.isSuccess || res.data == null) return;
|
||||||
// endpoint لیست body نمیفرستد، پس برای هر آیتم detail کامل را
|
|
||||||
// میگیریم تا videoUrl پر شود.
|
|
||||||
final fetches = res.data!.data.map((c) async {
|
final fetches = res.data!.data.map((c) async {
|
||||||
final detail = await ContentService.instance.getContent(c.id);
|
final detail = await ContentService.instance.getContent(c.id);
|
||||||
if (detail.isSuccess && detail.data != null) {
|
if (detail.isSuccess && detail.data != null) {
|
||||||
|
|
@ -561,10 +557,51 @@ class MainPageState extends CoreProvier {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(backend-migration): `api.didvan.app/didvanVoice` فعلا در دسترس نیست.
|
static const String _didvanVoiceCategoryId =
|
||||||
// پس از پیادهسازی endpoint معادل در api2.didvan.com، این تابع را به آن
|
'a7f3c9e2-5b18-4d6a-9c7e-3f8b1d5e2a91';
|
||||||
// متصل کنید.
|
|
||||||
Future<void> _getDidvanVoice() async {
|
Future<void> _getDidvanVoice() async {
|
||||||
|
if (!AuthConfig.useLegacyApi) {
|
||||||
|
try {
|
||||||
|
final res = await ContentService.instance.getContents(
|
||||||
|
page: 1,
|
||||||
|
limit: 20,
|
||||||
|
filterStatus: _visibleStatusFilter,
|
||||||
|
categoryId: _didvanVoiceCategoryId,
|
||||||
|
sortBy: const [MapEntry('createdAt', 'DESC')],
|
||||||
|
);
|
||||||
|
if (!res.isSuccess || res.data == null) return;
|
||||||
|
// endpoint لیست body نمیفرستد، پس برای هر آیتم detail کامل را
|
||||||
|
// میگیریم تا audioUrl پر شود.
|
||||||
|
final fetches = res.data!.data.map((c) async {
|
||||||
|
final detail = await ContentService.instance.getContent(c.id);
|
||||||
|
if (detail.isSuccess && detail.data != null) {
|
||||||
|
return detail.data!;
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}).toList();
|
||||||
|
final fullItems = await Future.wait(fetches);
|
||||||
|
didvanVoiceList = fullItems
|
||||||
|
.map((c) => DidvanVoiceModel(
|
||||||
|
id: c.id.hashCode,
|
||||||
|
title: c.title,
|
||||||
|
file: c.audioUrl ?? '',
|
||||||
|
image: c.coverImage ?? '',
|
||||||
|
publishedAt: (c.publishedAt ?? c.createdAt)
|
||||||
|
?.toIso8601String() ??
|
||||||
|
DateTime.now().toIso8601String(),
|
||||||
|
))
|
||||||
|
.toList();
|
||||||
|
if (didvanVoiceList.isNotEmpty) {
|
||||||
|
didvanVoice = _pickLatestVoice(List.from(didvanVoiceList));
|
||||||
|
}
|
||||||
|
notifyListeners();
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint('❌ didvanVoice (content-service) failed: $e');
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final service = RequestService(RequestHelper.didvanVoice);
|
final service = RequestService(RequestHelper.didvanVoice);
|
||||||
await service.httpGet().timeout(_legacyTimeout);
|
await service.httpGet().timeout(_legacyTimeout);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue