passo_mobile_app/lib/sevices/passo/building/property_info_services.dart

75 lines
2.3 KiB
Dart
Raw Normal View History

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';
import 'package:unit2/model/passo/land_ref.dart';
import 'package:unit2/model/passo/property_info.dart';
import 'package:http/http.dart' as http;
class PropertyInfoService {
static final PropertyInfoService _instance = PropertyInfoService();
static PropertyInfoService get instance => _instance;
Future<List<PropertyInfo>> getpropertyInfo() async {
http.Response response = await http.get(Uri.parse(
'http://192.168.10.218:8000/api/rptass_app/bldgappr_details/'));
print(response.body);
if (response.statusCode == 200) {
final List result = jsonDecode(response.body)['data'];
return result.map(((e) => PropertyInfo.fromJson(e))).toList();
} else {
throw Exception(response.reasonPhrase);
}
}
Future<http.Response?> postPropertyInfo(PropertyInfo faas) async {
http.Response? response;
try {
response = await http.post(
Uri.parse(
"http://192.168.10.218:8000/api/rptass_app/bldgappr_details/"),
headers: {
HttpHeaders.contentTypeHeader: "application/json",
},
body: jsonEncode(faas.toJson()));
} catch (e) {
log(e.toString());
}
return response;
}
Future<http.Response?> bldgLocPutInfo(BldgLoc data, id) async {
http.Response? response;
try {
response = await http.put(Uri.parse(
// ignore: unnecessary_brace_in_string_interps
"http://192.168.10.218:8000/api/rptass_app/bldgappr_location/?bldgappr_details_id=${id}"),
headers: {
HttpHeaders.contentTypeHeader: "application/json",
},
body: jsonEncode(data.toJson()));
} catch (e) {
log(e.toString());
}
return response;
}
Future<http.Response?> landRefPutInfo(LandRef data, id) async {
http.Response? response;
try {
response = await http.put(Uri.parse(
// ignore: unnecessary_brace_in_string_interps
"http://192.168.10.218:8000/api/rptass_app/bldgappr_landref/?bldgappr_details_id=${id}"),
headers: {
HttpHeaders.contentTypeHeader: "application/json",
},
body: jsonEncode(data.toJson()));
} catch (e) {
log(e.toString());
}
return response;
}
}