2023-07-28 02:35:36 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
import 'dart:developer';
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
import 'package:unit2/model/passo/property_assessment.dart';
|
|
|
|
import 'package:http/http.dart' as http;
|
2023-09-01 03:22:48 +00:00
|
|
|
import 'package:unit2/model/passo/property_assessment_edit.dart';
|
|
|
|
import 'package:unit2/utils/request.dart';
|
|
|
|
import 'package:unit2/utils/urls.dart';
|
2023-07-28 02:35:36 +00:00
|
|
|
|
|
|
|
class PropertyAssessmentServices {
|
|
|
|
static final PropertyAssessmentServices _instance =
|
|
|
|
PropertyAssessmentServices();
|
|
|
|
static PropertyAssessmentServices get instance => _instance;
|
|
|
|
|
2023-09-01 03:22:48 +00:00
|
|
|
String xClientKey = "unitK3CQaXiWlPReDsBzmmwBZPd9Re1z";
|
|
|
|
String xClientKeySecret = "unitcYqAN7GGalyz";
|
|
|
|
|
|
|
|
Future<List<PropertyAssessment>> fetch(tempID) async {
|
|
|
|
String path = Url.instance.propertyAssessment();
|
|
|
|
Map<String, String> headers = {
|
|
|
|
'Content-Type': 'application/json; charset=UTF-8',
|
|
|
|
'X-Client-Key': xClientKey,
|
|
|
|
'X-Client-Secret': xClientKeySecret
|
|
|
|
};
|
|
|
|
Map<String, String> params = {
|
|
|
|
"bldgappr_details_id": tempID.toString(),
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
http.Response response = await Request.instance
|
|
|
|
.getRequest(param: params, path: path, headers: headers);
|
|
|
|
print('Assessment');
|
|
|
|
print(response.statusCode);
|
|
|
|
if (response.statusCode == 200) {
|
|
|
|
final List result = jsonDecode(response.body)['data'];
|
|
|
|
|
|
|
|
return result.map(((e) => PropertyAssessment.fromJson(e))).toList();
|
|
|
|
} else {
|
|
|
|
throw Exception(response.reasonPhrase);
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
throw e.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<http.Response?> add(PropertyAssessment assessment) async {
|
|
|
|
String path = Url.instance.propertyAssessment();
|
|
|
|
Map<String, String> headers = {
|
|
|
|
'Content-Type': 'application/json; charset=UTF-8',
|
|
|
|
'X-Client-Key': xClientKey,
|
|
|
|
'X-Client-Secret': xClientKeySecret
|
|
|
|
};
|
|
|
|
http.Response? response;
|
|
|
|
|
|
|
|
try {
|
|
|
|
response = await Request.instance.postRequest(
|
|
|
|
param: {}, path: path, body: assessment.toJson(), headers: headers);
|
|
|
|
} catch (e) {
|
|
|
|
log(e.toString());
|
|
|
|
}
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<http.Response?> update(PropertyAssessment assessment, id) async {
|
|
|
|
String path = Url.instance.propertyAssessment();
|
|
|
|
Map<String, String> headers = {
|
|
|
|
'Content-Type': 'application/json; charset=UTF-8',
|
|
|
|
'X-Client-Key': xClientKey,
|
|
|
|
'X-Client-Secret': xClientKeySecret
|
|
|
|
};
|
|
|
|
Map<String, String> params = {
|
|
|
|
"bldgappr_details_id": id.toString(),
|
|
|
|
};
|
|
|
|
http.Response? response;
|
|
|
|
try {
|
|
|
|
response = await Request.instance.putRequest(
|
|
|
|
path: path,
|
|
|
|
body: assessment.toJson(),
|
|
|
|
headers: headers,
|
|
|
|
param: params);
|
|
|
|
} catch (e) {
|
|
|
|
log(e.toString());
|
|
|
|
}
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<PropertyAssessmentEdit> fetchEdit(tempID) async {
|
|
|
|
String path = Url.instance.propertyAssessment();
|
|
|
|
Map<String, String> headers = {
|
|
|
|
'Content-Type': 'application/json; charset=UTF-8',
|
|
|
|
'X-Client-Key': xClientKey,
|
|
|
|
'X-Client-Secret': xClientKeySecret
|
|
|
|
};
|
|
|
|
Map<String, String> params = {
|
|
|
|
"bldgappr_details_id": tempID.toString(),
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
http.Response response = await Request.instance
|
|
|
|
.getRequest(param: params, path: path, headers: headers);
|
|
|
|
print('Assessment');
|
2023-09-22 08:00:14 +00:00
|
|
|
print(response.statusCode);
|
2023-09-01 03:22:48 +00:00
|
|
|
print(response.body);
|
|
|
|
if (response.statusCode == 200) {
|
|
|
|
final jsonData = jsonDecode(response.body);
|
|
|
|
final dataList = jsonData['data'] as List<dynamic>;
|
|
|
|
final result = PropertyAssessmentEdit.fromJson(
|
|
|
|
dataList[0] as Map<String, dynamic>);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
} else {
|
|
|
|
throw Exception(response.reasonPhrase);
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
throw e.toString();
|
2023-07-28 02:35:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-01 03:22:48 +00:00
|
|
|
Future<http.Response?> addEdit(PropertyAssessmentEdit assessment) async {
|
|
|
|
Map<dynamic, dynamic> statusResponse = {};
|
|
|
|
String path = Url.instance.propertyAssessment();
|
|
|
|
Map<String, String> headers = {
|
|
|
|
'Content-Type': 'application/json; charset=UTF-8',
|
|
|
|
'X-Client-Key': xClientKey,
|
|
|
|
'X-Client-Secret': xClientKeySecret
|
|
|
|
};
|
2023-07-28 02:35:36 +00:00
|
|
|
http.Response? response;
|
|
|
|
try {
|
2023-09-01 03:22:48 +00:00
|
|
|
response = await Request.instance.postRequest(
|
|
|
|
param: {}, path: path, body: assessment.toJson(), headers: headers);
|
2023-07-28 02:35:36 +00:00
|
|
|
} catch (e) {
|
|
|
|
log(e.toString());
|
|
|
|
}
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2023-09-01 03:22:48 +00:00
|
|
|
Future<http.Response?> updateEdit(
|
|
|
|
PropertyAssessmentEdit assessment, id) async {
|
|
|
|
String path = Url.instance.propertyAssessment();
|
|
|
|
Map<String, String> headers = {
|
|
|
|
'Content-Type': 'application/json; charset=UTF-8',
|
|
|
|
'X-Client-Key': xClientKey,
|
|
|
|
'X-Client-Secret': xClientKeySecret
|
|
|
|
};
|
|
|
|
Map<String, String> params = {
|
|
|
|
"id": id.toString(),
|
|
|
|
};
|
2023-07-28 02:35:36 +00:00
|
|
|
http.Response? response;
|
|
|
|
try {
|
2023-09-01 03:22:48 +00:00
|
|
|
response = await Request.instance.putRequest(
|
|
|
|
path: path,
|
|
|
|
body: assessment.toJson(),
|
|
|
|
headers: headers,
|
|
|
|
param: params);
|
2023-07-28 02:35:36 +00:00
|
|
|
} catch (e) {
|
|
|
|
log(e.toString());
|
|
|
|
}
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
}
|