From 8317dc74afe67be6853312f617ac6de50b608c61 Mon Sep 17 00:00:00 2001 From: "Mr.Jebelli" Date: Mon, 22 Jun 2026 14:21:19 +0330 Subject: [PATCH] use ContentService (not legacy endpoint) for didvanvoice list --- .../home_widget_repository.dart | 64 +++++++++++-------- 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/lib/services/app_home_widget/home_widget_repository.dart b/lib/services/app_home_widget/home_widget_repository.dart index 2c5a2e4..ef3d8ec 100644 --- a/lib/services/app_home_widget/home_widget_repository.dart +++ b/lib/services/app_home_widget/home_widget_repository.dart @@ -2,6 +2,7 @@ import 'package:didvan/models/notification_message.dart'; import 'package:didvan/models/didvan_voice_model.dart'; import 'package:didvan/models/didvan_plus_model.dart'; import 'package:didvan/services/app_initalizer.dart'; +import 'package:didvan/services/content/content_service.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:home_widget/home_widget.dart'; @@ -326,32 +327,45 @@ class HomeWidgetRepository { case 'didvanvoice': case 'media': - // DidvanVoiceList expects List. The notification - // doesn't carry the full list, so we fetch it on the fly the same - // way the legacy int-id branch does. + // The list page expects List. New content is + // served by content-service (UUID); we fetch it by category id + // the same way main_page_state._getDidvanVoice does, then turn + // each row into a DidvanVoiceModel. + const didvanVoiceCategoryId = + 'a7f3c9e2-5b18-4d6a-9c7e-3f8b1d5e2a91'; try { - final service = RequestService(RequestHelper.didvanVoice); - await service.httpGet(); - if (service.statusCode == 200) { - final rawData = service.data('result'); - List voices = []; - if (rawData is List && rawData.isNotEmpty) { - voices = rawData - .map((e) => DidvanVoiceModel.fromJson( - Map.from(e as Map))) - .toList(); - } else if (rawData is Map) { - voices = [ - DidvanVoiceModel.fromJson( - Map.from(rawData)), - ]; - } - if (voices.isNotEmpty) { - route = Routes.didvanVoiceList; - args = voices; - } else { - route = Routes.home; - } + final res = await ContentService.instance.getContents( + page: 1, + limit: 20, + categoryId: didvanVoiceCategoryId, + sortBy: const [MapEntry('createdAt', 'DESC')], + ); + if (!res.isSuccess || res.data == null) { + route = Routes.home; + break; + } + // List endpoint doesn't return body — fetch detail for each + // item to get the audio URL. + 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); + final voices = 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 (voices.isNotEmpty) { + route = Routes.didvanVoiceList; + args = voices; } else { route = Routes.home; }