2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-06-17 04:35:26 +00:00

API post request now uses HttpClient

This commit is contained in:
Oliver Walters
2021-04-19 21:56:20 +10:00
parent 71340da068
commit b8c535560d
6 changed files with 118 additions and 103 deletions

View File

@ -262,36 +262,13 @@ class InvenTreeModel {
InvenTreeModel _model;
await api.post(URL, body: data).timeout(Duration(seconds: 10)).catchError((e) {
print("Error during CREATE");
print(e.toString());
if (e is SocketException) {
showServerError(
I18N.of(context).connectionRefused,
e.toString()
);
}
else if (e is TimeoutException) {
showTimeoutError(context);
} else {
// Re-throw the error
throw e;
}
var response = await api.post(URL, body: data);
if (response == null) {
return null;
})
.then((http.Response response) {
// Server should return HTTP_201_CREATED
if (response.statusCode == 201) {
var decoded = json.decode(response.body);
_model = createFromJson(decoded);
} else {
showStatusCodeError(response.statusCode);
}
});
}
return _model;
return createFromJson(response);
}
Future<InvenTreePageResponse> listPaginated(int limit, int offset, {Map<String, String> filters}) async {

View File

@ -437,31 +437,14 @@ class InvenTreeStockItem extends InvenTreeModel {
endpoint,
body: {
"item": {
"pk": "${pk}",
"quantity": "${q}",
"pk": "${pk}",
"quantity": "${q}",
},
"notes": notes ?? '',
}).timeout(Duration(seconds: 10)).catchError((error) {
if (error is TimeoutException) {
showTimeoutError(context);
} else if (error is SocketException) {
showServerError(
I18N.of(context).connectionRefused,
error.toString()
);
} else {
// Re-throw the error
throw error;
}
);
// Null response if error
return null;
});
if (response == null) return false;
if (response.statusCode != 200) {
showStatusCodeError(response.statusCode);
if (response == null) {
return false;
}
@ -508,9 +491,13 @@ class InvenTreeStockItem extends InvenTreeModel {
data["item"]["quantity"] = "${quantity}";
}
print("transfer stock!");
final response = await api.post("/stock/transfer/", body: data);
return (response.statusCode == 200);
print("transfer response: ${response}");
return response != null;
}
}