Settings
This commit is contained in:
parent
ddf550a963
commit
2ab1785968
|
|
@ -61,7 +61,8 @@ class ClientRepository {
|
|||
if (action != null) {
|
||||
url += '&action=' + action.toString();
|
||||
}
|
||||
response = await webClient.put(url, credentials.token, json.encode(data));
|
||||
response =
|
||||
await webClient.put(url, credentials.token, data: json.encode(data));
|
||||
}
|
||||
|
||||
final ClientItemResponse clientResponse =
|
||||
|
|
|
|||
|
|
@ -68,8 +68,8 @@ class DocumentRepository {
|
|||
if (action != null) {
|
||||
url += '?action=' + action.toString();
|
||||
}
|
||||
response =
|
||||
await webClient.put(url, credentials.token, json.encode(data));
|
||||
response = await webClient.put(url, credentials.token,
|
||||
data: json.encode(data));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,8 @@ class ExpenseRepository {
|
|||
if (action != null) {
|
||||
url += '?action=' + action.toString();
|
||||
}
|
||||
response = await webClient.put(url, credentials.token, json.encode(data));
|
||||
response =
|
||||
await webClient.put(url, credentials.token, data: json.encode(data));
|
||||
}
|
||||
|
||||
final ExpenseItemResponse expenseResponse =
|
||||
|
|
|
|||
|
|
@ -58,7 +58,8 @@ class InvoiceRepository {
|
|||
if (action != null) {
|
||||
url += '?action=' + action.toString();
|
||||
}
|
||||
response = await webClient.put(url, credentials.token, json.encode(data));
|
||||
response =
|
||||
await webClient.put(url, credentials.token, data: json.encode(data));
|
||||
}
|
||||
|
||||
final InvoiceItemResponse invoiceResponse =
|
||||
|
|
|
|||
|
|
@ -51,7 +51,8 @@ class PaymentRepository {
|
|||
if (action != null) {
|
||||
url += '&action=' + action.toString();
|
||||
}
|
||||
response = await webClient.put(url, credentials.token, json.encode(data));
|
||||
response =
|
||||
await webClient.put(url, credentials.token, data: json.encode(data));
|
||||
}
|
||||
|
||||
final PaymentItemResponse paymentResponse =
|
||||
|
|
|
|||
|
|
@ -45,7 +45,8 @@ class ProductRepository {
|
|||
if (action != null) {
|
||||
url += '?action=' + action.toString();
|
||||
}
|
||||
response = await webClient.put(url, credentials.token, json.encode(data));
|
||||
response =
|
||||
await webClient.put(url, credentials.token, data: json.encode(data));
|
||||
}
|
||||
|
||||
final ProductItemResponse productResponse =
|
||||
|
|
|
|||
|
|
@ -56,7 +56,8 @@ class ProjectRepository {
|
|||
if (action != null) {
|
||||
url += '?action=' + action.toString();
|
||||
}
|
||||
response = await webClient.put(url, credentials.token, json.encode(data));
|
||||
response =
|
||||
await webClient.put(url, credentials.token, data: json.encode(data));
|
||||
}
|
||||
|
||||
final ProjectItemResponse projectResponse =
|
||||
|
|
|
|||
|
|
@ -58,7 +58,8 @@ class QuoteRepository {
|
|||
if (action != null) {
|
||||
url += '?action=' + action.toString();
|
||||
}
|
||||
response = await webClient.put(url, credentials.token, json.encode(data));
|
||||
response =
|
||||
await webClient.put(url, credentials.token, data: json.encode(data));
|
||||
}
|
||||
|
||||
final InvoiceItemResponse quoteResponse =
|
||||
|
|
|
|||
|
|
@ -21,7 +21,8 @@ class SettingsRepository {
|
|||
dynamic response;
|
||||
|
||||
final url = credentials.url + '/companies/${company.id}';
|
||||
response = await webClient.put(url, credentials.token, json.encode(data));
|
||||
response =
|
||||
await webClient.put(url, credentials.token, data: json.encode(data));
|
||||
|
||||
final LoginResponse clientResponse =
|
||||
serializers.deserializeWith(LoginResponse.serializer, response);
|
||||
|
|
@ -34,7 +35,8 @@ class SettingsRepository {
|
|||
dynamic response;
|
||||
|
||||
final url = credentials.url + '/users/${user.id}';
|
||||
response = await webClient.put(url, credentials.token, json.encode(data));
|
||||
response =
|
||||
await webClient.put(url, credentials.token, data: json.encode(data));
|
||||
|
||||
final UserItemResponse userResponse =
|
||||
serializers.deserializeWith(UserItemResponse.serializer, response);
|
||||
|
|
@ -46,7 +48,9 @@ class SettingsRepository {
|
|||
final url = '${credentials.url}/companies';
|
||||
|
||||
final dynamic response = await webClient.post(url, credentials.token,
|
||||
data: {'name': 'logo'}, filePath: path, fileIndex: 'logo');
|
||||
filePath: path,
|
||||
fileIndex: 'logo',
|
||||
data: {'_method': 'PUT', 'name': 'TEST'});
|
||||
|
||||
debugPrint('### UPLOAD LOGO RESPONSE: $response');
|
||||
|
||||
|
|
|
|||
|
|
@ -61,7 +61,8 @@ class TaskRepository {
|
|||
if (action != null) {
|
||||
url += '?action=' + action.toString();
|
||||
}
|
||||
response = await webClient.put(url, credentials.token, json.encode(data));
|
||||
response =
|
||||
await webClient.put(url, credentials.token, data: json.encode(data));
|
||||
}
|
||||
|
||||
final TaskItemResponse taskResponse =
|
||||
|
|
|
|||
|
|
@ -56,7 +56,8 @@ class VendorRepository {
|
|||
if (action != null) {
|
||||
url += '?action=' + action.toString();
|
||||
}
|
||||
response = await webClient.put(url, credentials.token, json.encode(data));
|
||||
response =
|
||||
await webClient.put(url, credentials.token, data: json.encode(data));
|
||||
}
|
||||
|
||||
final VendorItemResponse vendorResponse =
|
||||
|
|
|
|||
|
|
@ -36,25 +36,15 @@ class WebClient {
|
|||
}
|
||||
|
||||
Future<dynamic> post(String url, String token,
|
||||
{dynamic data, String filePath, String fileIndex = 'file'}) async {
|
||||
{dynamic data, String filePath, String fileIndex}) async {
|
||||
url = _checkUrl(url);
|
||||
print('POST: $url');
|
||||
print('Data: $data');
|
||||
http.Response response;
|
||||
|
||||
if (filePath != null) {
|
||||
final file = File(filePath);
|
||||
final stream = http.ByteStream(DelegatingStream.typed(file.openRead()));
|
||||
final length = await file.length();
|
||||
|
||||
final request = http.MultipartRequest('POST', Uri.parse(url))
|
||||
..fields.addAll(data ?? {})
|
||||
..headers.addAll(_getHeaders(token))
|
||||
..files.add(http.MultipartFile(fileIndex, stream, length,
|
||||
filename: basename(file.path)));
|
||||
|
||||
response = await http.Response.fromStream(await request.send())
|
||||
.timeout(const Duration(minutes: 10));
|
||||
response = await _uploadFile(url, token, filePath,
|
||||
fileIndex: fileIndex, data: data);
|
||||
} else {
|
||||
response = await http.Client()
|
||||
.post(url, body: data, headers: _getHeaders(token))
|
||||
|
|
@ -66,16 +56,24 @@ class WebClient {
|
|||
return json.decode(response.body);
|
||||
}
|
||||
|
||||
Future<dynamic> put(String url, String token, dynamic data) async {
|
||||
Future<dynamic> put(String url, String token,
|
||||
{dynamic data, String filePath, String fileIndex = 'file'}) async {
|
||||
url = _checkUrl(url);
|
||||
print('PUT: $url');
|
||||
print('Data: $data');
|
||||
|
||||
final http.Response response = await http.Client().put(
|
||||
url,
|
||||
body: data,
|
||||
headers: _getHeaders(token),
|
||||
);
|
||||
http.Response response;
|
||||
|
||||
if (filePath != null) {
|
||||
response = await _uploadFile(url, token, filePath,
|
||||
fileIndex: fileIndex, data: data, method: 'PUT');
|
||||
} else {
|
||||
response = await http.Client().put(
|
||||
url,
|
||||
body: data,
|
||||
headers: _getHeaders(token),
|
||||
);
|
||||
}
|
||||
|
||||
_checkResponse(response);
|
||||
|
||||
|
|
@ -180,3 +178,19 @@ bool _isVersionSupported(String version) {
|
|||
minor >= kMinMinorAppVersion &&
|
||||
patch >= kMinPatchAppVersion;
|
||||
}
|
||||
|
||||
Future<http.Response> _uploadFile(String url, String token, String filePath,
|
||||
{String method = 'POST', String fileIndex = 'file', dynamic data}) async {
|
||||
final file = File(filePath);
|
||||
final stream = http.ByteStream(DelegatingStream.typed(file.openRead()));
|
||||
final length = await file.length();
|
||||
|
||||
final request = http.MultipartRequest(method, Uri.parse(url))
|
||||
..fields.addAll(data ?? {})
|
||||
..headers.addAll(_getHeaders(token))
|
||||
..files.add(http.MultipartFile(fileIndex, stream, length,
|
||||
filename: basename(file.path)));
|
||||
|
||||
return await http.Response.fromStream(await request.send())
|
||||
.timeout(const Duration(minutes: 10));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ class StubRepository {
|
|||
if (action != null) {
|
||||
url += '?action=' + action.toString();
|
||||
}
|
||||
response = await webClient.put(url, credentials.token, json.encode(data));
|
||||
response = await webClient.put(url, credentials.token, data: json.encode(data));
|
||||
}
|
||||
|
||||
final StubItemResponse stubResponse =
|
||||
|
|
|
|||
Loading…
Reference in New Issue