change the structure of Track Gas Refill and Transfer Device (point 2 & 3)
parent
1e06449d8d
commit
198dc95814
@ -0,0 +1,81 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:test_sa/api/api_client.dart';
|
||||||
|
import 'package:test_sa/api/user_api_client.dart';
|
||||||
|
|
||||||
|
import '../controllers/api_routes/urls.dart';
|
||||||
|
import '../models/device/device_transfer.dart';
|
||||||
|
import '../models/device/device_transfer_info.dart';
|
||||||
|
|
||||||
|
class DeviceTransferApiClient{
|
||||||
|
|
||||||
|
static final DeviceTransferApiClient _instance =DeviceTransferApiClient._internal();
|
||||||
|
|
||||||
|
DeviceTransferApiClient._internal();
|
||||||
|
|
||||||
|
factory DeviceTransferApiClient() =>_instance;
|
||||||
|
|
||||||
|
Future<List<DeviceTransfer>> getRequests({
|
||||||
|
required List items,
|
||||||
|
required int pageItemNumber
|
||||||
|
}) async {
|
||||||
|
|
||||||
|
final response = await ApiClient().getJsonForResponse(
|
||||||
|
"${URLs.host1}${URLs.getDeviceTransfer}",
|
||||||
|
queryParameters: {
|
||||||
|
"uid":"${UserApiClient().user?.id}",
|
||||||
|
"token":"${UserApiClient().user?.token}",
|
||||||
|
"page":"${(items.length) ~/ pageItemNumber}",
|
||||||
|
},
|
||||||
|
headers: {"Content-Type": "application/json; charset=utf-8"}
|
||||||
|
);
|
||||||
|
|
||||||
|
List listJson = json.decode(utf8.decode(response.bodyBytes).replaceAll("\\", ""));
|
||||||
|
return listJson.map((request) => DeviceTransfer.fromJson(request)).toList();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<DeviceTransfer> createRequest({
|
||||||
|
required DeviceTransfer model,
|
||||||
|
})async{
|
||||||
|
Map<String, dynamic> body = {
|
||||||
|
"uid": UserApiClient().user?.id.toString()??"",
|
||||||
|
"token": UserApiClient().user?.token??"",
|
||||||
|
"serial_id": model.device?.id??"",
|
||||||
|
"destination_client": model.receiver?.client?.id??"",
|
||||||
|
"destination_department": model.receiver?.department?.id??"",
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
final response = await ApiClient().postJsonForResponse(
|
||||||
|
"${URLs.host1}${URLs.requestDeviceTransfer}", body, isFormData: true);
|
||||||
|
|
||||||
|
return DeviceTransfer.fromJson(json.decode(utf8.decode(response.bodyBytes))[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Future<DeviceTransfer> updateRequest({
|
||||||
|
required bool isSender,
|
||||||
|
required String requestId,
|
||||||
|
required DeviceTransfer? oldModel,
|
||||||
|
required DeviceTransferInfo newModel,
|
||||||
|
})async{
|
||||||
|
|
||||||
|
Map<String, dynamic> body = {
|
||||||
|
"uid": UserApiClient().user?.id.toString(),
|
||||||
|
"token": UserApiClient().user?.token,
|
||||||
|
"current_user": UserApiClient().user?.id,
|
||||||
|
};
|
||||||
|
|
||||||
|
body.addAll(newModel.toJson(isSender));
|
||||||
|
|
||||||
|
final response = await ApiClient().postJsonForResponse(
|
||||||
|
"${URLs.host1}${URLs.updateDeviceTransfer}/$requestId", body);
|
||||||
|
|
||||||
|
return DeviceTransfer.fromJson(
|
||||||
|
json.decode(utf8.decode(response.bodyBytes))[0]
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue