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) {
|
||||
final newestContent = list.contents.first;
|
||||
|
||||
// Debug for monthly items
|
||||
if (list.type == 'monthly') {
|
||||
debugPrint(
|
||||
'🔍 MONTHLY in carousel - ID: ${newestContent.id}, File: ${newestContent.file}, Link: ${newestContent.link}');
|
||||
|
|
@ -402,7 +401,6 @@ class _IndustryPulseSection extends StatelessWidget {
|
|||
placeholder: const SizedBox.shrink(),
|
||||
onRetry: () => context.read<NewStatisticState>().init(),
|
||||
builder: (context, statState) {
|
||||
// همهی آیتمها را از همه گروهها جمع میکنیم.
|
||||
final items = <stat.Content>[];
|
||||
for (final cat in statState.contents) {
|
||||
items.addAll(cat.contents);
|
||||
|
|
|
|||
|
|
@ -103,11 +103,11 @@ class MainPageState extends CoreProvier {
|
|||
_fetchStories(),
|
||||
_getSwotItems(),
|
||||
_getDidvanPlus(),
|
||||
_getDidvanVoice(),
|
||||
];
|
||||
if (AuthConfig.useLegacyApi) {
|
||||
tasks.addAll([
|
||||
_getMainPageContent(),
|
||||
_getDidvanVoice(),
|
||||
_getTopBanner(),
|
||||
]);
|
||||
} else {
|
||||
|
|
@ -485,12 +485,10 @@ class MainPageState extends CoreProvier {
|
|||
}
|
||||
}
|
||||
|
||||
/// شناسهی دستهی «دیدوان پلاس» در content-service.
|
||||
static const String _didvanPlusCategoryId =
|
||||
'e4c8a3b1-9d27-4e6f-bf3d-2a1c8e5f4d12';
|
||||
|
||||
Future<void> _getDidvanPlus() async {
|
||||
// مسیر جدید: content-service.
|
||||
if (!AuthConfig.useLegacyApi) {
|
||||
try {
|
||||
final res = await ContentService.instance.getContents(
|
||||
|
|
@ -501,8 +499,6 @@ class MainPageState extends CoreProvier {
|
|||
sortBy: const [MapEntry('createdAt', 'DESC')],
|
||||
);
|
||||
if (!res.isSuccess || res.data == null) return;
|
||||
// endpoint لیست body نمیفرستد، پس برای هر آیتم detail کامل را
|
||||
// میگیریم تا videoUrl پر شود.
|
||||
final fetches = res.data!.data.map((c) async {
|
||||
final detail = await ContentService.instance.getContent(c.id);
|
||||
if (detail.isSuccess && detail.data != null) {
|
||||
|
|
@ -561,10 +557,51 @@ class MainPageState extends CoreProvier {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO(backend-migration): `api.didvan.app/didvanVoice` فعلا در دسترس نیست.
|
||||
// پس از پیادهسازی endpoint معادل در api2.didvan.com، این تابع را به آن
|
||||
// متصل کنید.
|
||||
static const String _didvanVoiceCategoryId =
|
||||
'a7f3c9e2-5b18-4d6a-9c7e-3f8b1d5e2a91';
|
||||
|
||||
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 {
|
||||
final service = RequestService(RequestHelper.didvanVoice);
|
||||
await service.httpGet().timeout(_legacyTimeout);
|
||||
|
|
|
|||
Loading…
Reference in New Issue