Refactor code
This commit is contained in:
parent
1ea4106ad2
commit
059317d58b
|
|
@ -89,7 +89,7 @@ class ClientRepository {
|
||||||
|
|
||||||
final dynamic response = await webClient.post(
|
final dynamic response = await webClient.post(
|
||||||
'${credentials.url}/clients/${entity.id}/upload', credentials.token,
|
'${credentials.url}/clients/${entity.id}/upload', credentials.token,
|
||||||
data: fields, multipartFile: multipartFile);
|
data: fields, multipartFiles: [multipartFile]);
|
||||||
|
|
||||||
final ClientItemResponse clientResponse =
|
final ClientItemResponse clientResponse =
|
||||||
serializers.deserializeWith(ClientItemResponse.serializer, response);
|
serializers.deserializeWith(ClientItemResponse.serializer, response);
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ class CreditRepository {
|
||||||
|
|
||||||
final dynamic response = await webClient.post(
|
final dynamic response = await webClient.post(
|
||||||
'${credentials.url}/credits/${entity.id}/upload', credentials.token,
|
'${credentials.url}/credits/${entity.id}/upload', credentials.token,
|
||||||
data: fields, multipartFile: multipartFile);
|
data: fields, multipartFiles: [multipartFile]);
|
||||||
|
|
||||||
final InvoiceItemResponse invoiceResponse =
|
final InvoiceItemResponse invoiceResponse =
|
||||||
serializers.deserializeWith(InvoiceItemResponse.serializer, response);
|
serializers.deserializeWith(InvoiceItemResponse.serializer, response);
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ class ExpenseRepository {
|
||||||
|
|
||||||
final dynamic response = await webClient.post(
|
final dynamic response = await webClient.post(
|
||||||
'${credentials.url}/expenses/${entity.id}/upload', credentials.token,
|
'${credentials.url}/expenses/${entity.id}/upload', credentials.token,
|
||||||
data: fields, multipartFile: multipartFile);
|
data: fields, multipartFiles: [multipartFile]);
|
||||||
|
|
||||||
final ExpenseItemResponse expenseResponse =
|
final ExpenseItemResponse expenseResponse =
|
||||||
serializers.deserializeWith(ExpenseItemResponse.serializer, response);
|
serializers.deserializeWith(ExpenseItemResponse.serializer, response);
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ class GroupRepository {
|
||||||
'${credentials.url}/group_settings/${entity.id}/upload',
|
'${credentials.url}/group_settings/${entity.id}/upload',
|
||||||
credentials.token,
|
credentials.token,
|
||||||
data: fields,
|
data: fields,
|
||||||
multipartFile: multipartFile);
|
multipartFiles: [multipartFile]);
|
||||||
|
|
||||||
final GroupItemResponse groupResponse =
|
final GroupItemResponse groupResponse =
|
||||||
serializers.deserializeWith(GroupItemResponse.serializer, response);
|
serializers.deserializeWith(GroupItemResponse.serializer, response);
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,7 @@ class InvoiceRepository {
|
||||||
|
|
||||||
final dynamic response = await webClient.post(
|
final dynamic response = await webClient.post(
|
||||||
'${credentials.url}/invoices/${entity.id}/upload', credentials.token,
|
'${credentials.url}/invoices/${entity.id}/upload', credentials.token,
|
||||||
data: fields, multipartFile: multipartFile);
|
data: fields, multipartFiles: [multipartFile]);
|
||||||
|
|
||||||
final InvoiceItemResponse invoiceResponse =
|
final InvoiceItemResponse invoiceResponse =
|
||||||
serializers.deserializeWith(InvoiceItemResponse.serializer, response);
|
serializers.deserializeWith(InvoiceItemResponse.serializer, response);
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ class ProductRepository {
|
||||||
|
|
||||||
final dynamic response = await webClient.post(
|
final dynamic response = await webClient.post(
|
||||||
'${credentials.url}/products/${entity.id}/upload', credentials.token,
|
'${credentials.url}/products/${entity.id}/upload', credentials.token,
|
||||||
data: fields, multipartFile: multipartFile);
|
data: fields, multipartFiles: [multipartFile]);
|
||||||
|
|
||||||
final ProductItemResponse productResponse =
|
final ProductItemResponse productResponse =
|
||||||
serializers.deserializeWith(ProductItemResponse.serializer, response);
|
serializers.deserializeWith(ProductItemResponse.serializer, response);
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ class ProjectRepository {
|
||||||
|
|
||||||
final dynamic response = await webClient.post(
|
final dynamic response = await webClient.post(
|
||||||
'${credentials.url}/projects/${entity.id}/upload', credentials.token,
|
'${credentials.url}/projects/${entity.id}/upload', credentials.token,
|
||||||
data: fields, multipartFile: multipartFile);
|
data: fields, multipartFiles: [multipartFile]);
|
||||||
|
|
||||||
final ProjectItemResponse projectResponse =
|
final ProjectItemResponse projectResponse =
|
||||||
serializers.deserializeWith(ProjectItemResponse.serializer, response);
|
serializers.deserializeWith(ProjectItemResponse.serializer, response);
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ class QuoteRepository {
|
||||||
|
|
||||||
final dynamic response = await webClient.post(
|
final dynamic response = await webClient.post(
|
||||||
'${credentials.url}/quotes/${entity.id}/upload', credentials.token,
|
'${credentials.url}/quotes/${entity.id}/upload', credentials.token,
|
||||||
data: fields, multipartFile: multipartFile);
|
data: fields, multipartFiles: [multipartFile]);
|
||||||
|
|
||||||
final InvoiceItemResponse invoiceResponse =
|
final InvoiceItemResponse invoiceResponse =
|
||||||
serializers.deserializeWith(InvoiceItemResponse.serializer, response);
|
serializers.deserializeWith(InvoiceItemResponse.serializer, response);
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ class SettingsRepository {
|
||||||
final url = '${credentials.url}/$route/$entityId';
|
final url = '${credentials.url}/$route/$entityId';
|
||||||
|
|
||||||
final dynamic response = await webClient.post(url, credentials.token,
|
final dynamic response = await webClient.post(url, credentials.token,
|
||||||
data: {'_method': 'PUT'}, multipartFile: multipartFile);
|
data: {'_method': 'PUT'}, multipartFiles: [multipartFile]);
|
||||||
|
|
||||||
if (type == EntityType.client) {
|
if (type == EntityType.client) {
|
||||||
return serializers
|
return serializers
|
||||||
|
|
@ -102,7 +102,7 @@ class SettingsRepository {
|
||||||
|
|
||||||
final dynamic response = await webClient.post(
|
final dynamic response = await webClient.post(
|
||||||
'${credentials.url}/companies/${company.id}/upload', credentials.token,
|
'${credentials.url}/companies/${company.id}/upload', credentials.token,
|
||||||
data: fields, multipartFile: multipartFile);
|
data: fields, multipartFiles: [multipartFile]);
|
||||||
|
|
||||||
final CompanyItemResponse companyResponse =
|
final CompanyItemResponse companyResponse =
|
||||||
serializers.deserializeWith(CompanyItemResponse.serializer, response);
|
serializers.deserializeWith(CompanyItemResponse.serializer, response);
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ class TaskRepository {
|
||||||
|
|
||||||
final dynamic response = await webClient.post(
|
final dynamic response = await webClient.post(
|
||||||
'${credentials.url}/tasks/${entity.id}/upload', credentials.token,
|
'${credentials.url}/tasks/${entity.id}/upload', credentials.token,
|
||||||
data: fields, multipartFile: multipartFile);
|
data: fields, multipartFiles: [multipartFile]);
|
||||||
|
|
||||||
final TaskItemResponse taskResponse =
|
final TaskItemResponse taskResponse =
|
||||||
serializers.deserializeWith(TaskItemResponse.serializer, response);
|
serializers.deserializeWith(TaskItemResponse.serializer, response);
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ class VendorRepository {
|
||||||
|
|
||||||
final dynamic response = await webClient.post(
|
final dynamic response = await webClient.post(
|
||||||
'${credentials.url}/vendors/${entity.id}/upload', credentials.token,
|
'${credentials.url}/vendors/${entity.id}/upload', credentials.token,
|
||||||
data: fields, multipartFile: multipartFile);
|
data: fields, multipartFiles: [multipartFile]);
|
||||||
|
|
||||||
final VendorItemResponse vendorResponse =
|
final VendorItemResponse vendorResponse =
|
||||||
serializers.deserializeWith(VendorItemResponse.serializer, response);
|
serializers.deserializeWith(VendorItemResponse.serializer, response);
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,6 @@ class WebClient {
|
||||||
String url,
|
String url,
|
||||||
String token, {
|
String token, {
|
||||||
dynamic data,
|
dynamic data,
|
||||||
MultipartFile multipartFile,
|
|
||||||
List<MultipartFile> multipartFiles,
|
List<MultipartFile> multipartFiles,
|
||||||
String secret,
|
String secret,
|
||||||
String password,
|
String password,
|
||||||
|
|
@ -74,14 +73,6 @@ class WebClient {
|
||||||
}
|
}
|
||||||
http.Response response;
|
http.Response response;
|
||||||
|
|
||||||
if (multipartFile != null) {
|
|
||||||
if (multipartFiles == null) {
|
|
||||||
multipartFiles = [multipartFile];
|
|
||||||
} else {
|
|
||||||
multipartFiles.add(multipartFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (multipartFiles != null) {
|
if (multipartFiles != null) {
|
||||||
response = await _uploadFiles(url, token, multipartFiles, data: data);
|
response = await _uploadFiles(url, token, multipartFiles, data: data);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue