75 lines
2.3 KiB
Dart
75 lines
2.3 KiB
Dart
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;
|
|
}
|
|
}
|