Merge branch 'majd_development' into 'master'
change Api structure for request gas refill page + solve null safety bugs... See merge request haroon6138/cloudsolutions-atoms!13merge-requests/14/merge
commit
408eb92063
@ -0,0 +1,94 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:test_sa/api/user_api_client.dart';
|
||||||
|
|
||||||
|
import '../controllers/api_routes/urls.dart';
|
||||||
|
import '../models/gas_refill/gas_refill_model.dart';
|
||||||
|
import 'api_client.dart';
|
||||||
|
|
||||||
|
class GasRefillApiClient{
|
||||||
|
|
||||||
|
static final GasRefillApiClient _instance =GasRefillApiClient._internal();
|
||||||
|
|
||||||
|
GasRefillApiClient._internal();
|
||||||
|
|
||||||
|
factory GasRefillApiClient() =>_instance;
|
||||||
|
|
||||||
|
|
||||||
|
Future<List<GasRefillModel>> getRequestPages({
|
||||||
|
required List items,
|
||||||
|
required int pageItemNumber
|
||||||
|
}) async {
|
||||||
|
|
||||||
|
final response = await ApiClient().getJsonForResponse(
|
||||||
|
"${URLs.host1}${URLs.getGasRefill}",//body
|
||||||
|
headers: {"Content-Type": "application/json; charset=utf-8"},
|
||||||
|
queryParameters: {
|
||||||
|
"uid":"${UserApiClient().user?.id}",
|
||||||
|
"token":"${UserApiClient().user?.token}",
|
||||||
|
"page":"${(items.length) ~/ pageItemNumber}",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// client's request was successfully received
|
||||||
|
List requestsListJson = json.decode(utf8.decode(response.bodyBytes));
|
||||||
|
return requestsListJson.map((request) => GasRefillModel.fromJson(request)).toList();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<GasRefillModel> createModel({
|
||||||
|
required GasRefillModel model,
|
||||||
|
}) async{
|
||||||
|
|
||||||
|
Map<String, dynamic> body = {
|
||||||
|
"uid": UserApiClient().user?.id.toString(),
|
||||||
|
"token": UserApiClient().user?.token ?? "",
|
||||||
|
"title": model.title ?? "",
|
||||||
|
"status": "0", //model.status.value.toString(),
|
||||||
|
};
|
||||||
|
|
||||||
|
body["details"] = jsonEncode(model.details
|
||||||
|
?.map((model) => {
|
||||||
|
"type": model.type?.id.toString(),
|
||||||
|
"size": model.cylinderSize?.id.toString(),
|
||||||
|
"requsted_qty": model.requestedQuantity.toString(),
|
||||||
|
})
|
||||||
|
.toList());
|
||||||
|
|
||||||
|
final response = await ApiClient().postJsonForResponse(
|
||||||
|
"${URLs.host1}${URLs.requestGasRefill}",
|
||||||
|
body,
|
||||||
|
);
|
||||||
|
|
||||||
|
return GasRefillModel.fromJson(json.decode(utf8.decode(response.bodyBytes))[0]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Future updateModel({
|
||||||
|
required GasRefillModel? oldModel,
|
||||||
|
required GasRefillModel newModel,
|
||||||
|
})async{
|
||||||
|
Map<String, dynamic> body = {
|
||||||
|
"uid": UserApiClient().user?.id.toString(),
|
||||||
|
"token": UserApiClient().user?.token,
|
||||||
|
"title": newModel.title,
|
||||||
|
"status": newModel.status?.id.toString(),
|
||||||
|
};
|
||||||
|
|
||||||
|
body["details"] = jsonEncode(newModel.details
|
||||||
|
?.map((model) => {
|
||||||
|
"type": model.type?.id.toString(),
|
||||||
|
"size": model.cylinderSize?.id.toString(),
|
||||||
|
"requsted_qty": model.requestedQuantity.toString(),
|
||||||
|
"deliverd_qty": model.deliveredQuantity.toString(),
|
||||||
|
})
|
||||||
|
.toList());
|
||||||
|
|
||||||
|
final reponse = await ApiClient().postJsonForResponse(
|
||||||
|
"${URLs.host1}${URLs.updateGasRefill}/${newModel.id}",
|
||||||
|
body);
|
||||||
|
|
||||||
|
oldModel?.fromGasRefillModel(newModel);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue