feat: add monthly category
This commit is contained in:
parent
a805689c53
commit
b67613abc5
|
|
@ -1,9 +1,11 @@
|
|||
import 'dart:convert';
|
||||
import 'package:didvan/config/auth_config.dart';
|
||||
import 'package:didvan/constants/assets.dart';
|
||||
import 'package:didvan/models/category.dart';
|
||||
import 'package:didvan/models/enums.dart';
|
||||
import 'package:didvan/models/monthly/monthly_model.dart';
|
||||
import 'package:didvan/providers/core.dart';
|
||||
import 'package:didvan/services/content/content_service.dart';
|
||||
import 'package:didvan/services/network/request.dart';
|
||||
import 'package:didvan/services/network/request_helper.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
|
@ -56,10 +58,68 @@ class MonthlyListState extends CoreProvier {
|
|||
|
||||
bool get searching => searchQuery.isNotEmpty;
|
||||
|
||||
/// شناسهی دستهی «ماهنامه» در content-service.
|
||||
static const String _monthlyCategoryId =
|
||||
'd5e8b2c4-7f31-4a92-bc6f-8e2a5d1c3b47';
|
||||
|
||||
Future<void> fetchMonthlyList() async {
|
||||
appState = AppState.busy;
|
||||
notifyListeners();
|
||||
|
||||
// مسیر جدید: content-service.
|
||||
if (!AuthConfig.useLegacyApi) {
|
||||
try {
|
||||
final res = await ContentService.instance.getContents(
|
||||
page: 1,
|
||||
limit: 30,
|
||||
filterStatus: '\$in:accepted,published',
|
||||
categoryId: _monthlyCategoryId,
|
||||
sortBy: const [MapEntry('createdAt', 'DESC')],
|
||||
);
|
||||
if (!res.isSuccess || res.data == null) {
|
||||
appState = AppState.failed;
|
||||
notifyListeners();
|
||||
return;
|
||||
}
|
||||
// endpoint لیست body نمیفرستد، پس برای هر آیتم detail کامل را
|
||||
// میگیریم تا fileUrl پر شود.
|
||||
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);
|
||||
_allMonthlyItems = fullItems.map((c) {
|
||||
final fileUrl = c.videoUrl ?? c.audioUrl ?? '';
|
||||
final dateIso = (c.publishedAt ?? c.createdAt)?.toIso8601String() ??
|
||||
DateTime.now().toIso8601String();
|
||||
return MonthlyItem(
|
||||
id: c.id.hashCode,
|
||||
title: c.title,
|
||||
image: c.coverImage ?? '',
|
||||
description: c.summary ?? '',
|
||||
pageNumber: 0,
|
||||
publishedAt: dateIso,
|
||||
file: fileUrl,
|
||||
link: null,
|
||||
tags: const <MonthlyTag>[],
|
||||
isLiked: c.isLiked,
|
||||
isBookmarked: c.isBookmarked,
|
||||
);
|
||||
}).toList();
|
||||
monthlyItems = _applyFilters(_allMonthlyItems);
|
||||
appState = AppState.idle;
|
||||
} catch (e) {
|
||||
debugPrint('❌ monthly (content-service) failed: $e');
|
||||
appState = AppState.failed;
|
||||
}
|
||||
notifyListeners();
|
||||
return;
|
||||
}
|
||||
|
||||
// مسیر legacy.
|
||||
try {
|
||||
const url = '${RequestHelper.baseUrl}/monthly';
|
||||
debugPrint('Fetching monthly list from: $url');
|
||||
|
|
|
|||
Loading…
Reference in New Issue