use ContentService (not legacy endpoint) for didvanvoice list
This commit is contained in:
parent
2253c71338
commit
8317dc74af
|
|
@ -2,6 +2,7 @@ import 'package:didvan/models/notification_message.dart';
|
||||||
import 'package:didvan/models/didvan_voice_model.dart';
|
import 'package:didvan/models/didvan_voice_model.dart';
|
||||||
import 'package:didvan/models/didvan_plus_model.dart';
|
import 'package:didvan/models/didvan_plus_model.dart';
|
||||||
import 'package:didvan/services/app_initalizer.dart';
|
import 'package:didvan/services/app_initalizer.dart';
|
||||||
|
import 'package:didvan/services/content/content_service.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:home_widget/home_widget.dart';
|
import 'package:home_widget/home_widget.dart';
|
||||||
|
|
@ -326,32 +327,45 @@ class HomeWidgetRepository {
|
||||||
|
|
||||||
case 'didvanvoice':
|
case 'didvanvoice':
|
||||||
case 'media':
|
case 'media':
|
||||||
// DidvanVoiceList expects List<DidvanVoiceModel>. The notification
|
// The list page expects List<DidvanVoiceModel>. New content is
|
||||||
// doesn't carry the full list, so we fetch it on the fly the same
|
// served by content-service (UUID); we fetch it by category id
|
||||||
// way the legacy int-id branch does.
|
// the same way main_page_state._getDidvanVoice does, then turn
|
||||||
|
// each row into a DidvanVoiceModel.
|
||||||
|
const didvanVoiceCategoryId =
|
||||||
|
'a7f3c9e2-5b18-4d6a-9c7e-3f8b1d5e2a91';
|
||||||
try {
|
try {
|
||||||
final service = RequestService(RequestHelper.didvanVoice);
|
final res = await ContentService.instance.getContents(
|
||||||
await service.httpGet();
|
page: 1,
|
||||||
if (service.statusCode == 200) {
|
limit: 20,
|
||||||
final rawData = service.data('result');
|
categoryId: didvanVoiceCategoryId,
|
||||||
List<DidvanVoiceModel> voices = [];
|
sortBy: const [MapEntry('createdAt', 'DESC')],
|
||||||
if (rawData is List && rawData.isNotEmpty) {
|
);
|
||||||
voices = rawData
|
if (!res.isSuccess || res.data == null) {
|
||||||
.map((e) => DidvanVoiceModel.fromJson(
|
route = Routes.home;
|
||||||
Map<String, dynamic>.from(e as Map)))
|
break;
|
||||||
.toList();
|
}
|
||||||
} else if (rawData is Map) {
|
// List endpoint doesn't return body — fetch detail for each
|
||||||
voices = [
|
// item to get the audio URL.
|
||||||
DidvanVoiceModel.fromJson(
|
final fetches = res.data!.data.map((c) async {
|
||||||
Map<String, dynamic>.from(rawData)),
|
final detail = await ContentService.instance.getContent(c.id);
|
||||||
];
|
if (detail.isSuccess && detail.data != null) return detail.data!;
|
||||||
}
|
return c;
|
||||||
if (voices.isNotEmpty) {
|
}).toList();
|
||||||
route = Routes.didvanVoiceList;
|
final fullItems = await Future.wait(fetches);
|
||||||
args = voices;
|
final voices = fullItems
|
||||||
} else {
|
.map((c) => DidvanVoiceModel(
|
||||||
route = Routes.home;
|
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 {
|
} else {
|
||||||
route = Routes.home;
|
route = Routes.home;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue