Initial commit: Uruk Prize Platform architecture, backend core, mobile app, gateway caller & deployment pipeline
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../../core/network/api_client.dart';
|
||||
import 'partners_state.dart';
|
||||
|
||||
class PartnersCubit extends Cubit<PartnersState> {
|
||||
final ApiClient _apiClient;
|
||||
|
||||
PartnersCubit({ApiClient? apiClient})
|
||||
: _apiClient = apiClient ?? ApiClient(),
|
||||
super(PartnersInitial());
|
||||
|
||||
Future<void> fetchPartners({String type = 'ALL', String country = 'ALL', String? search}) async {
|
||||
emit(PartnersLoading());
|
||||
try {
|
||||
final queryParams = <String, String>{};
|
||||
if (type != 'ALL') queryParams['type'] = type;
|
||||
if (country != 'ALL') queryParams['country'] = country;
|
||||
if (search != null && search.isNotEmpty) queryParams['search'] = search;
|
||||
|
||||
final res = await _apiClient.get(
|
||||
'/api/v1/partners',
|
||||
queryParams: queryParams,
|
||||
requiresAuth: false,
|
||||
);
|
||||
|
||||
final list = (res['data'] as List<dynamic>?) ?? [];
|
||||
emit(PartnersLoaded(
|
||||
partners: list,
|
||||
selectedType: type,
|
||||
selectedCountry: country,
|
||||
));
|
||||
} catch (e) {
|
||||
emit(PartnersFailure(e.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user