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