|
|
@ -7,60 +7,48 @@ import '../controllers/api_routes/urls.dart';
|
|
|
|
import '../models/device/device_transfer.dart';
|
|
|
|
import '../models/device/device_transfer.dart';
|
|
|
|
import '../models/device/device_transfer_info.dart';
|
|
|
|
import '../models/device/device_transfer_info.dart';
|
|
|
|
|
|
|
|
|
|
|
|
class DeviceTransferApiClient{
|
|
|
|
class DeviceTransferApiClient {
|
|
|
|
|
|
|
|
static final DeviceTransferApiClient _instance = DeviceTransferApiClient._internal();
|
|
|
|
static final DeviceTransferApiClient _instance =DeviceTransferApiClient._internal();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DeviceTransferApiClient._internal();
|
|
|
|
DeviceTransferApiClient._internal();
|
|
|
|
|
|
|
|
|
|
|
|
factory DeviceTransferApiClient() =>_instance;
|
|
|
|
factory DeviceTransferApiClient() => _instance;
|
|
|
|
|
|
|
|
|
|
|
|
Future<List<DeviceTransfer>> getRequests({
|
|
|
|
|
|
|
|
required List items,
|
|
|
|
|
|
|
|
required int pageItemNumber
|
|
|
|
|
|
|
|
}) async {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final response = await ApiClient().getJsonForResponse(
|
|
|
|
Future<List<DeviceTransfer>> getRequests({required List items, required int pageItemNumber}) async {
|
|
|
|
"${URLs.host1}${URLs.getDeviceTransfer}",
|
|
|
|
final response = await ApiClient().getJsonForResponse("${URLs.host1}${URLs.getDeviceTransfer}", queryParameters: {
|
|
|
|
queryParameters: {
|
|
|
|
"uid": "${UserApiClient().user?.id}",
|
|
|
|
"uid":"${UserApiClient().user?.id}",
|
|
|
|
"token": "${UserApiClient().user?.token}",
|
|
|
|
"token":"${UserApiClient().user?.token}",
|
|
|
|
"page": "${(items.length) ~/ pageItemNumber}",
|
|
|
|
"page":"${(items.length) ~/ pageItemNumber}",
|
|
|
|
}, headers: {
|
|
|
|
},
|
|
|
|
"Content-Type": "application/json; charset=utf-8"
|
|
|
|
headers: {"Content-Type": "application/json; charset=utf-8"}
|
|
|
|
});
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List listJson = json.decode(utf8.decode(response.bodyBytes).replaceAll("\\", ""));
|
|
|
|
List listJson = json.decode(utf8.decode(response.bodyBytes).replaceAll("\\", ""));
|
|
|
|
return listJson.map((request) => DeviceTransfer.fromJson(request)).toList();
|
|
|
|
return listJson.map((request) => DeviceTransfer.fromJson(request)).toList();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<DeviceTransfer> createRequest({
|
|
|
|
Future<DeviceTransfer> createRequest({
|
|
|
|
required DeviceTransfer model,
|
|
|
|
required DeviceTransfer model,
|
|
|
|
})async{
|
|
|
|
}) async {
|
|
|
|
Map<String, dynamic> body = {
|
|
|
|
Map<String, dynamic> body = {
|
|
|
|
"uid": UserApiClient().user?.id.toString()??"",
|
|
|
|
"uid": UserApiClient().user?.id.toString() ?? "",
|
|
|
|
"token": UserApiClient().user?.token??"",
|
|
|
|
"token": UserApiClient().user?.token ?? "",
|
|
|
|
"serial_id": model.device?.id??"",
|
|
|
|
"serial_id": model.device?.id ?? "",
|
|
|
|
"destination_client": model.receiver?.client?.id??"",
|
|
|
|
"destination_client": model.receiver?.client?.id ?? "",
|
|
|
|
"destination_department": model.receiver?.department?.id??"",
|
|
|
|
"destination_department": model.receiver?.department?.id ?? "",
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final response = await ApiClient().postJsonForResponse("${URLs.host1}${URLs.requestDeviceTransfer}", body, isFormData: true);
|
|
|
|
final response = await ApiClient().postJsonForResponse(
|
|
|
|
|
|
|
|
"${URLs.host1}${URLs.requestDeviceTransfer}", body, isFormData: true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return DeviceTransfer.fromJson(json.decode(utf8.decode(response.bodyBytes))[0]);
|
|
|
|
return DeviceTransfer.fromJson(json.decode(utf8.decode(response.bodyBytes))[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<DeviceTransfer> updateRequest({
|
|
|
|
Future<DeviceTransfer> updateRequest({
|
|
|
|
required bool isSender,
|
|
|
|
required bool isSender,
|
|
|
|
required String requestId,
|
|
|
|
required String requestId,
|
|
|
|
required DeviceTransfer? oldModel,
|
|
|
|
required DeviceTransfer? oldModel,
|
|
|
|
required DeviceTransferInfo newModel,
|
|
|
|
required DeviceTransferInfo newModel,
|
|
|
|
})async{
|
|
|
|
}) async {
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, dynamic> body = {
|
|
|
|
Map<String, dynamic> body = {
|
|
|
|
"uid": UserApiClient().user?.id.toString(),
|
|
|
|
"uid": UserApiClient().user?.id.toString(),
|
|
|
|
"token": UserApiClient().user?.token,
|
|
|
|
"token": UserApiClient().user?.token,
|
|
|
@ -69,13 +57,8 @@ class DeviceTransferApiClient{
|
|
|
|
|
|
|
|
|
|
|
|
body.addAll(newModel.toJson(isSender));
|
|
|
|
body.addAll(newModel.toJson(isSender));
|
|
|
|
|
|
|
|
|
|
|
|
final response = await ApiClient().postJsonForResponse(
|
|
|
|
final response = await ApiClient().postJsonForResponse("${URLs.host1}${URLs.updateDeviceTransfer}/$requestId", body);
|
|
|
|
"${URLs.host1}${URLs.updateDeviceTransfer}/$requestId", body);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return DeviceTransfer.fromJson(
|
|
|
|
|
|
|
|
json.decode(utf8.decode(response.bodyBytes))[0]
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return DeviceTransfer.fromJson(json.decode(utf8.decode(response.bodyBytes))[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|