Initial commit: Uruk Prize Platform architecture, backend core, mobile app, gateway caller & deployment pipeline
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../../core/network/api_client.dart';
|
||||
import 'membership_state.dart';
|
||||
|
||||
class MembershipCubit extends Cubit<MembershipState> {
|
||||
final ApiClient _apiClient;
|
||||
|
||||
MembershipCubit({ApiClient? apiClient})
|
||||
: _apiClient = apiClient ?? ApiClient(),
|
||||
super(MembershipInitial());
|
||||
|
||||
Future<void> fetchCardDetails() async {
|
||||
emit(MembershipLoading());
|
||||
try {
|
||||
final res = await _apiClient.get('/api/v1/subscription/my-card');
|
||||
final data = res['data'] as Map<String, dynamic>;
|
||||
emit(MembershipLoaded(cardData: data));
|
||||
} on ApiException catch (e) {
|
||||
if (e.statusCode == 404) {
|
||||
emit(MembershipNotSubscribed());
|
||||
} else {
|
||||
emit(MembershipFailure(e.message));
|
||||
}
|
||||
} catch (e) {
|
||||
emit(MembershipFailure(e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> refreshDynamicQr() async {
|
||||
if (state is! MembershipLoaded) return;
|
||||
final current = state as MembershipLoaded;
|
||||
|
||||
try {
|
||||
final res = await _apiClient.get('/api/v1/qr/dynamic-token');
|
||||
final data = res['data'] as Map<String, dynamic>;
|
||||
|
||||
emit(current.copyWith(
|
||||
dynamicQrToken: data['token'] as String?,
|
||||
qrValidUntil: data['valid_until'] as int?,
|
||||
));
|
||||
} catch (e) {
|
||||
emit(MembershipFailure('تعذر تحديث كود التحقق: $e'));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user