list method
Future<ApiResponseModel<List<ChallengeModel> > >
list({
- required String companyId,
- ChallengeType? type,
- ChallengeStatus? status,
Lists available challenges.
companyId is the company ID.
type is an optional filter by challenge type.
status is an optional filter by challenge status.
Returns a list of ChallengeModel instances.
Implementation
Future<ApiResponseModel<List<ChallengeModel>>> list({
required String companyId,
ChallengeType? type,
ChallengeStatus? status,
}) async {
final url = "$_baseUrl/challenges";
final payload = {
'apiKey': _apiKey,
'companyId': companyId,
if (type != null) 'type': type.value,
if (status != null) 'status': status.value,
};
debugPrint("flutter_mon_sms_pro/challenges/list/payload: $payload");
final r = await _dio.post(url, data: payload);
debugPrint("flutter_mon_sms_pro/challenges/list/data: ${r.data}");
final response = ApiResponseModel.fromJson(
r.data,
(data) => (data as List<dynamic>)
.map((e) => ChallengeModel.fromJson(e as Map<String, dynamic>))
.toList(),
);
return response;
}