2023-07-28 02:35:36 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
import 'dart:developer';
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
import 'package:unit2/model/passo/bldg_loc.dart';
|
2023-09-01 03:22:48 +00:00
|
|
|
import 'package:unit2/model/passo/general_description.dart';
|
2023-07-28 02:35:36 +00:00
|
|
|
import 'package:unit2/model/passo/land_ref.dart';
|
|
|
|
import 'package:unit2/model/passo/property_info.dart';
|
|
|
|
import 'package:http/http.dart' as http;
|
2023-09-01 03:22:48 +00:00
|
|
|
import 'package:unit2/utils/request.dart';
|
|
|
|
import 'package:unit2/utils/urls.dart';
|
2023-07-28 02:35:36 +00:00
|
|
|
|
|
|
|
class PropertyInfoService {
|
|
|
|
static final PropertyInfoService _instance = PropertyInfoService();
|
|
|
|
static PropertyInfoService get instance => _instance;
|
2023-09-01 03:22:48 +00:00
|
|
|
String xClientKey = "unitK3CQaXiWlPReDsBzmmwBZPd9Re1z";
|
|
|
|
String xClientKeySecret = "unitcYqAN7GGalyz";
|
2023-07-28 02:35:36 +00:00
|
|
|
|
2023-09-01 03:22:48 +00:00
|
|
|
Future<List<PropertyInfo>> fetch() async {
|
|
|
|
String path = Url.instance.propertyInfo();
|
|
|
|
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
|
|
|
|
2023-09-01 03:22:48 +00:00
|
|
|
try {
|
|
|
|
http.Response response = await Request.instance
|
|
|
|
.getRequest(param: {}, path: path, headers: headers);
|
|
|
|
if (response.statusCode == 200) {
|
|
|
|
final List result = jsonDecode(response.body)['data'];
|
|
|
|
|
|
|
|
return result.map(((e) => PropertyInfo.fromJson(e))).toList();
|
|
|
|
} else {
|
|
|
|
throw Exception(response.reasonPhrase);
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
throw e.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<http.Response?> add(PropertyInfo faas) async {
|
|
|
|
Map<dynamic, dynamic> statusResponse = {};
|
|
|
|
String path = Url.instance.propertyInfo();
|
|
|
|
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: faas.toJson(), headers: headers);
|
|
|
|
} catch (e) {
|
|
|
|
throw e.toString();
|
2023-07-28 02:35:36 +00:00
|
|
|
}
|
2023-09-01 03:22:48 +00:00
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<http.Response?> update(PropertyInfo data, id) async {
|
|
|
|
String path = "${Url.instance.propertyInfo()}$id/";
|
|
|
|
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.putRequest(
|
|
|
|
path: path, body: data.toJson(), headers: headers, param: {});
|
|
|
|
} catch (e) {
|
|
|
|
throw e.toString();
|
|
|
|
}
|
|
|
|
return response;
|
2023-07-28 02:35:36 +00:00
|
|
|
}
|
|
|
|
|
2023-09-01 03:22:48 +00:00
|
|
|
Future<http.Response?> updateBldg(BldgLoc data, id) async {
|
|
|
|
String path = Url.instance.bldgLocation();
|
|
|
|
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(),
|
|
|
|
};
|
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: data.toJson(), headers: headers, param: params);
|
2023-07-28 02:35:36 +00:00
|
|
|
} catch (e) {
|
2023-09-01 03:22:48 +00:00
|
|
|
throw e.toString();
|
2023-07-28 02:35:36 +00:00
|
|
|
}
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2023-09-01 03:22:48 +00:00
|
|
|
Future<http.Response?> updateLandRef(LandRef data, id) async {
|
|
|
|
String path = Url.instance.landRef();
|
|
|
|
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(),
|
|
|
|
};
|
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: data.toJson(), headers: headers, param: params);
|
2023-07-28 02:35:36 +00:00
|
|
|
} catch (e) {
|
2023-09-01 03:22:48 +00:00
|
|
|
throw e.toString();
|
2023-07-28 02:35:36 +00:00
|
|
|
}
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2023-09-01 03:22:48 +00:00
|
|
|
Future<http.Response?> updateGenDesc(GeneralDesc data, id) async {
|
|
|
|
String path = Url.instance.generalDescription();
|
|
|
|
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(),
|
|
|
|
};
|
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: data.toJson(), headers: headers, param: params);
|
2023-07-28 02:35:36 +00:00
|
|
|
} catch (e) {
|
2023-09-01 03:22:48 +00:00
|
|
|
throw e.toString();
|
2023-07-28 02:35:36 +00:00
|
|
|
}
|
|
|
|
return response;
|
|
|
|
}
|
2023-09-12 08:33:07 +00:00
|
|
|
|
|
|
|
Future<http.Response> remove(id) async {
|
|
|
|
String path = Url.instance.propertyInfo();
|
|
|
|
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(),
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
http.Response response = await Request.instance
|
|
|
|
.deleteRequest(path: path, headers: headers, body: {}, param: params);
|
|
|
|
print(id);
|
|
|
|
if (response.statusCode == 200) {
|
|
|
|
print(response.body);
|
|
|
|
return response;
|
|
|
|
} else {
|
|
|
|
throw Exception(response.reasonPhrase);
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
throw e.toString();
|
|
|
|
}
|
|
|
|
}
|
2023-07-28 02:35:36 +00:00
|
|
|
}
|