passo_mobile_app/lib/sevices/profile/eligibility_services.dart

78 lines
2.4 KiB
Dart

import 'dart:convert';
import 'package:unit2/model/profile/eligibility.dart';
import 'package:unit2/utils/request.dart';
import 'package:unit2/utils/urls.dart';
import 'package:http/http.dart' as http;
class EligibilityService {
static final EligibilityService _instance = EligibilityService();
static EligibilityService get instance => _instance;
Future<bool> delete(
{required int eligibilityId,
required int profileId,
required String token}) async {
bool? success;
String authtoken = "Token $token";
String path = "${Url.instance.deleteEligibility()}$profileId/";
Map body = {"eligibility_id": eligibilityId};
Map<String, dynamic> params = {"force_mode": "true"};
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': authtoken
};
// try{
http.Response response = await Request.instance
.deleteRequest(path: path, headers: headers, body: body, param: params);
if (response.statusCode == 200) {
Map data = jsonDecode(response.body);
success = data['success'];
} else {
success = false;
}
// }catch(e){
// throw(e.toString());
// }
return success!;
}
Future<Map<dynamic, dynamic>> add(
{required EligibityCert eligibityCert,
required String token,
required int profileId}) async {
Map<dynamic, dynamic>? _response={};
String authtoken = "Token $token+1";
String path = '${Url.instance.addEligibility()}$profileId/';
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': authtoken
};
Map body = {
'eligibility_id': eligibityCert.eligibility!.id,
'license_number': eligibityCert.licenseNumber,
'exam_date': eligibityCert.examDate?.toString(),
'validity_date': eligibityCert.validityDate?.toString(),
'rating': eligibityCert.rating,
'_citymunCode': eligibityCert.examAddress?.cityMunicipality?.code,
'_countryId': eligibityCert.examAddress?.country!.id
};
try {
http.Response response = await Request.instance
.postRequest(path: path, body: body, headers: headers, param: {});
if (response.statusCode == 201) {
Map data = jsonDecode(response.body);
_response = data;
} else {
_response.addAll({'success':false});
}
return _response;
} catch (e) {
throw e.toString();
}
}
}