2023-09-01 03:22:48 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
import 'dart:developer';
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
import 'package:http/http.dart' as http;
|
|
|
|
import 'package:unit2/model/passo/land_appr.dart';
|
|
|
|
import 'package:unit2/model/passo/land_value_adjustment.dart';
|
|
|
|
import 'package:unit2/model/passo/other_improvements.dart';
|
|
|
|
import 'package:unit2/utils/request.dart';
|
|
|
|
|
|
|
|
import '../../../utils/urls.dart';
|
|
|
|
|
|
|
|
class ValueAdjustmentsServices {
|
|
|
|
static final ValueAdjustmentsServices _instance = ValueAdjustmentsServices();
|
|
|
|
static ValueAdjustmentsServices get instance => _instance;
|
|
|
|
|
|
|
|
String xClientKey = "unitK3CQaXiWlPReDsBzmmwBZPd9Re1z";
|
|
|
|
String xClientKeySecret = "unitcYqAN7GGalyz";
|
|
|
|
|
|
|
|
Future<List<ValueAdjustments>> fetch(tempID) async {
|
|
|
|
String path = Url.instance.getValueAdjustmentss();
|
|
|
|
Map<String, String> headers = {
|
|
|
|
'Content-Type': 'application/json; charset=UTF-8',
|
|
|
|
'X-Client-Key': xClientKey,
|
|
|
|
'X-Client-Secret': xClientKeySecret
|
|
|
|
};
|
|
|
|
Map<String, String> params = {
|
2023-09-22 08:00:14 +00:00
|
|
|
"landappr_details_id": tempID.toString(),
|
2023-09-01 03:22:48 +00:00
|
|
|
};
|
|
|
|
try {
|
|
|
|
http.Response response = await Request.instance
|
2023-09-22 08:00:14 +00:00
|
|
|
.getRequest(param: params, path: path, headers: headers);
|
2023-09-01 03:22:48 +00:00
|
|
|
if (response.statusCode == 200) {
|
|
|
|
final List result = jsonDecode(response.body)['data'];
|
|
|
|
print(result);
|
|
|
|
return result.map(((e) => ValueAdjustments.fromJson(e))).toList();
|
|
|
|
} else {
|
|
|
|
throw Exception(response.reasonPhrase);
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
throw e.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<http.Response?> add(ValueAdjustments items) async {
|
|
|
|
String path = Url.instance.getValueAdjustmentss();
|
|
|
|
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: items.toJson(), headers: headers);
|
|
|
|
} catch (e) {
|
|
|
|
log(e.toString());
|
|
|
|
}
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<http.Response> remove(id) async {
|
|
|
|
String path = Url.instance.getValueAdjustmentss();
|
|
|
|
Map<String, String> headers = {
|
|
|
|
'Content-Type': 'application/json; charset=UTF-8',
|
|
|
|
'X-Client-Key': xClientKey,
|
|
|
|
'X-Client-Secret': xClientKeySecret
|
|
|
|
};
|
|
|
|
Map<String, String> params = {
|
2023-09-22 08:00:14 +00:00
|
|
|
"id": id.toString(),
|
2023-09-01 03:22:48 +00:00
|
|
|
};
|
|
|
|
try {
|
|
|
|
http.Response response = await Request.instance
|
2023-09-22 08:00:14 +00:00
|
|
|
.deleteRequest(path: path, headers: headers, body: {}, param: params);
|
2023-09-01 03:22:48 +00:00
|
|
|
print(id);
|
|
|
|
if (response.statusCode == 200) {
|
|
|
|
print(response.body);
|
|
|
|
return response;
|
|
|
|
} else {
|
|
|
|
throw Exception(response.reasonPhrase);
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
throw e.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|