feat: add front chat

This commit is contained in:
2026-06-25 23:34:10 +03:30
parent fa45ef0737
commit 153b4caa3d
8 changed files with 377 additions and 140 deletions
@@ -0,0 +1,33 @@
import '../../../../../core/locator/locator.dart';
import '../../../../../core/network/api_provider_imp.dart';
import '../../../domain/entities/chat_pack.dart';
/// دادهٔ بسته‌های چت از backend (دریافتِ بسته‌ها و خریدِ بسته با سکه).
class ChatApiProvider {
ApiProviderImp get _api => locator<ApiProviderImp>();
Future<List<ChatPack>> getChatPacks() async {
final res = await _api.get('/chat-packs');
if (res.statusCode != 200) {
throw Exception('chat-packs: ${res.statusCode}');
}
final list = (res.data['packs'] as List?) ?? const [];
return list
.map((e) => ChatPack.fromJson(Map<String, dynamic>.from(e as Map)))
.toList();
}
/// خریدِ بسته. در صورتِ موفقیت null، وگرنه پیامِ خطای فارسی برمی‌گرداند.
Future<String?> buyChatPack(String packId) async {
final res = await _api.post('/shop/buy-chat-pack', body: {'pack_id': packId});
if (res.statusCode == 200) return null;
switch (res.statusCode) {
case 402:
return 'سکهٔ کافی ندارید';
case 409:
return 'این بسته را دارید';
default:
return 'خرید ناموفق بود';
}
}
}