2023-02-23 00:53:14 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
|
2023-02-27 06:26:27 +00:00
|
|
|
import 'package:unit2/model/profile/eligibility.dart';
|
2023-02-23 00:53:14 +00:00
|
|
|
import 'package:unit2/utils/request.dart';
|
|
|
|
import 'package:unit2/utils/urls.dart';
|
|
|
|
import 'package:http/http.dart' as http;
|
2023-02-27 06:26:27 +00:00
|
|
|
|
|
|
|
class EligibilityService {
|
2023-02-23 00:53:14 +00:00
|
|
|
static final EligibilityService _instance = EligibilityService();
|
|
|
|
static EligibilityService get instance => _instance;
|
|
|
|
|
2023-02-27 06:26:27 +00:00
|
|
|
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 = {
|
2023-02-23 00:53:14 +00:00
|
|
|
'Content-Type': 'application/json; charset=UTF-8',
|
2023-02-27 06:26:27 +00:00
|
|
|
'Authorization': authtoken
|
2023-02-23 00:53:14 +00:00
|
|
|
};
|
|
|
|
// try{
|
2023-02-27 06:26:27 +00:00
|
|
|
http.Response response = await Request.instance
|
|
|
|
.deleteRequest(path: path, headers: headers, body: body, param: params);
|
|
|
|
if (response.statusCode == 200) {
|
|
|
|
Map data = jsonDecode(response.body);
|
2023-02-23 00:53:14 +00:00
|
|
|
success = data['success'];
|
2023-02-27 06:26:27 +00:00
|
|
|
} else {
|
2023-02-23 00:53:14 +00:00
|
|
|
success = false;
|
2023-02-27 06:26:27 +00:00
|
|
|
}
|
|
|
|
|
2023-02-23 00:53:14 +00:00
|
|
|
// }catch(e){
|
|
|
|
// throw(e.toString());
|
|
|
|
// }
|
|
|
|
return success!;
|
|
|
|
}
|
|
|
|
|
2023-02-27 06:26:27 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|