You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.4 KiB
Dart
42 lines
1.4 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:test_sa/api/api_client.dart';
|
|
import 'package:test_sa/api/user_api_client.dart';
|
|
import 'package:test_sa/models/service_request/service_request.dart';
|
|
|
|
import '../controllers/api_routes/urls.dart';
|
|
|
|
class ServiceRequestApiClient {
|
|
static final ServiceRequestApiClient _instance = ServiceRequestApiClient._internal();
|
|
final List<ServiceRequest> serviceRequests = [];
|
|
|
|
ServiceRequestApiClient._internal();
|
|
|
|
factory ServiceRequestApiClient() => _instance;
|
|
|
|
/// ### The result will be added to [serviceRequests]
|
|
Future createRequest(ServiceRequest serviceRequest) async {
|
|
final user = UserApiClient().user;
|
|
await ApiClient().postJsonForObject(
|
|
(json) {
|
|
// ServiceRequest.fromJson(json.decode(utf8.decode(response.bodyBytes))[0])
|
|
serviceRequests.insert(0, ServiceRequest.fromJson(json[0]));
|
|
},
|
|
'${URLs.host1}${URLs.createRequest}',
|
|
{
|
|
"uid": user?.id,
|
|
"token": user?.token ?? "",
|
|
"sn_id": serviceRequest.deviceId ?? "",
|
|
"date": (DateTime.now().millisecondsSinceEpoch).toString(),
|
|
"client": user?.hospital?.id ?? '',
|
|
"complaint": serviceRequest.maintenanceIssue,
|
|
"image": json.encode(serviceRequest.devicePhotos),
|
|
"priority": (serviceRequest.priority?.id).toString(),
|
|
"defect_types": (serviceRequest.defectType?.id).toString(),
|
|
"audio": serviceRequest.audio,
|
|
},
|
|
isFormData: true,
|
|
);
|
|
}
|
|
}
|