2023-07-28 02:21:42 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
import 'package:unit2/screens/profile/components/other_information/org_membership/add_modal.dart';
|
|
|
|
import 'package:unit2/utils/request.dart';
|
|
|
|
import 'package:unit2/utils/urls.dart';
|
|
|
|
|
|
|
|
import '../../../model/utils/agency.dart';
|
|
|
|
import 'package:http/http.dart' as http;
|
|
|
|
|
|
|
|
class AgencyServices {
|
|
|
|
static final AgencyServices _instance = AgencyServices();
|
|
|
|
static AgencyServices get instance => _instance;
|
|
|
|
String xClientKey = "unitK3CQaXiWlPReDsBzmmwBZPd9Re1z";
|
|
|
|
String xClientKeySecret = "unitcYqAN7GGalyz";
|
|
|
|
|
|
|
|
Future<List<Agency>> getAgencies() async {
|
|
|
|
List<Agency> agencies = [];
|
|
|
|
String path = Url.instance.agencies();
|
|
|
|
Map<String, String> headers = {
|
|
|
|
'Content-Type': 'application/json; charset=UTF-8',
|
|
|
|
'X-Client-Key': xClientKey,
|
|
|
|
'X-Client-Secret': xClientKeySecret
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
http.Response response = await Request.instance
|
|
|
|
.getRequest(path: path, headers: headers, param: {});
|
|
|
|
if (response.statusCode == 200) {
|
|
|
|
Map data = jsonDecode(response.body);
|
|
|
|
if (data['data'] != null) {
|
|
|
|
for (var element in data['data']) {
|
|
|
|
Agency newAgency = Agency.fromJson(element);
|
|
|
|
agencies.add(newAgency);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
throw e.toString();
|
|
|
|
}
|
|
|
|
return agencies;
|
|
|
|
}
|
|
|
|
Future<Map<dynamic,dynamic>>add({required Agency agency})async{
|
|
|
|
Map<dynamic, dynamic> statusResponse = {};
|
|
|
|
String path = Url.instance.postAgencies();
|
|
|
|
Map<String, String> headers = {
|
|
|
|
'Content-Type': 'application/json; charset=UTF-8',
|
|
|
|
'X-Client-Key': xClientKey,
|
|
|
|
'X-Client-Secret': xClientKeySecret
|
|
|
|
};
|
|
|
|
Map body = {
|
|
|
|
"name":agency.name,
|
|
|
|
"category_id":agency.category!.id,
|
|
|
|
"private_entity":agency.privateEntity,
|
|
|
|
"contact_info":null,
|
|
|
|
};
|
|
|
|
try{
|
|
|
|
http.Response response = await Request.instance.postRequest(param: {},path: path, body: body,headers: headers);
|
|
|
|
if(response.statusCode == 201){
|
|
|
|
Map data = jsonDecode(response.body);
|
|
|
|
statusResponse = data;
|
|
|
|
}else{
|
2023-08-22 06:22:08 +00:00
|
|
|
Map data = jsonDecode(response.body);
|
2023-07-28 02:21:42 +00:00
|
|
|
String message = data['message'];
|
|
|
|
statusResponse.addAll({'message': message});
|
|
|
|
statusResponse.addAll(
|
|
|
|
{'success': false},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}catch(e){
|
|
|
|
throw e.toString();
|
|
|
|
}
|
|
|
|
return statusResponse;
|
|
|
|
}
|
|
|
|
}
|