62 lines
1.9 KiB
Dart
62 lines
1.9 KiB
Dart
import 'dart:convert';
|
|
import 'dart:developer';
|
|
import 'dart:io';
|
|
|
|
import 'package:unit2/model/passo/property_assessment.dart';
|
|
import 'package:http/http.dart' as http;
|
|
|
|
class PropertyAssessmentServices {
|
|
static final PropertyAssessmentServices _instance =
|
|
PropertyAssessmentServices();
|
|
static PropertyAssessmentServices get instance => _instance;
|
|
|
|
Future<List<PropertyAssessment>> getPropertyAssessment(tempID) async {
|
|
http.Response response = await http.get(Uri.parse(
|
|
'http://192.168.10.218:8000/api/rptass_app/property_assessment/?bldgappr_details_id=$tempID'));
|
|
print('Assessment');
|
|
print(response.statusCode);
|
|
if (response.statusCode == 200) {
|
|
final List result = jsonDecode(response.body)['data'];
|
|
|
|
return result.map(((e) => PropertyAssessment.fromJson(e))).toList();
|
|
} else {
|
|
throw Exception(response.reasonPhrase);
|
|
}
|
|
}
|
|
|
|
Future<http.Response?> postPropertyAssessment(
|
|
PropertyAssessment assessment) async {
|
|
http.Response? response;
|
|
try {
|
|
response = await http.post(
|
|
Uri.parse(
|
|
"http://192.168.10.218:8000/api/rptass_app/property_assessment/"),
|
|
headers: {
|
|
HttpHeaders.contentTypeHeader: "application/json",
|
|
},
|
|
body: jsonEncode(assessment.toJson()));
|
|
} catch (e) {
|
|
log(e.toString());
|
|
}
|
|
return response;
|
|
}
|
|
|
|
Future<http.Response?> propertyAssessmentPutInfo(
|
|
PropertyAssessment assessment, id) async {
|
|
print(id);
|
|
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/property_assessment/?bldgappr_details_id=${id}"),
|
|
headers: {
|
|
HttpHeaders.contentTypeHeader: "application/json",
|
|
},
|
|
body: jsonEncode(assessment.toJson()));
|
|
} catch (e) {
|
|
log(e.toString());
|
|
}
|
|
return response;
|
|
}
|
|
}
|