Merge branch 'master' into majd_development
# Conflicts: # lib/controllers/providers/api/devices_provider.dart # lib/views/widgets/equipment/auto_complete_devices_field.dartmerge-requests/16/head
commit
7e808e5bf4
@ -0,0 +1,52 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:test_sa/models/device/device.dart';
|
||||||
|
|
||||||
|
import '../controllers/api_routes/urls.dart';
|
||||||
|
import 'api_client.dart';
|
||||||
|
|
||||||
|
class DevicesApiClient {
|
||||||
|
static final DevicesApiClient _instance = DevicesApiClient._internal();
|
||||||
|
final List<Device> devices = [];
|
||||||
|
|
||||||
|
DevicesApiClient._internal();
|
||||||
|
|
||||||
|
factory DevicesApiClient() => _instance;
|
||||||
|
|
||||||
|
/// Fetch devices by [hospitalId] and insert the result into [devices] list
|
||||||
|
Future getEquipment(String hospitalId) async {
|
||||||
|
final response = await ApiClient().getJsonForResponse(URLs.host1 + URLs.getEquipment, queryParameters: {'client': hospitalId});
|
||||||
|
List equipmentListJson = json.decode(utf8.decode(response.bodyBytes));
|
||||||
|
devices.clear();
|
||||||
|
devices.addAll(equipmentListJson.map((device) => Device.fromJson(device)).toList());
|
||||||
|
debugPrint("devices : ${devices.length}");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns a list of devices by [hospitalId] and [serialNumber] (or | and) [number]
|
||||||
|
Future<List<Device>> getDevicesList({required String hospitalId, String? serialNumber, String? number}) async {
|
||||||
|
final response = await ApiClient().getJsonForResponse(
|
||||||
|
URLs.host1 + URLs.getEquipment,
|
||||||
|
queryParameters: {
|
||||||
|
'client': hospitalId,
|
||||||
|
if (serialNumber?.isEmpty == false) 'name': serialNumber,
|
||||||
|
if (number?.isEmpty == false) 'number': number,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
List categoriesListJson = json.decode(utf8.decode(response.bodyBytes));
|
||||||
|
return categoriesListJson.map((device) => Device.fromJson(device)).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns a list of devices by [hospitalId] (and optionally) [serialNumber]
|
||||||
|
Future<List<Device>> getDevicesListBySN({required String hospitalId, required String serialNumber}) async {
|
||||||
|
final response = await ApiClient().getJsonForResponse(
|
||||||
|
URLs.host1 + URLs.getEquipment,
|
||||||
|
queryParameters: {
|
||||||
|
'client': hospitalId,
|
||||||
|
if (serialNumber.isNotEmpty) 'serial_qr': serialNumber,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
List categoriesListJson = json.decode(utf8.decode(response.bodyBytes));
|
||||||
|
return categoriesListJson.map((device) => Device.fromJson(device)).toList();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,41 @@
|
|||||||
|
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,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue