181186 - Criar PDV Android para rodar em maquinas P.O.S.
This commit is contained in:
commit
c9983cbad5
204 files changed
+11453
No files matched your search
@@ -0,0 +1,29 @@
|
||||
import '../../domain/entities/customer.dart';
|
||||
import '../../domain/repositories/customer_repository.dart';
|
||||
import '../datasources/remote/odoo_session_api_client.dart';
|
||||
|
||||
class OdooCustomerRepository implements CustomerRepository {
|
||||
const OdooCustomerRepository({required this.apiClient});
|
||||
|
||||
final OdooSessionApiClient apiClient;
|
||||
|
||||
@override
|
||||
Future<List<Customer>> search(String query) async {
|
||||
try {
|
||||
final payload = await apiClient.postForm(
|
||||
'/pdv_pos/clientes',
|
||||
body: {'query': query.trim()},
|
||||
);
|
||||
final records = payload['customers'];
|
||||
if (records is! List) {
|
||||
throw const CustomerSearchException('Resposta de clientes inválida.');
|
||||
}
|
||||
return records
|
||||
.whereType<Map<String, dynamic>>()
|
||||
.map(Customer.fromJson)
|
||||
.toList(growable: false);
|
||||
} on OdooApiException catch (error) {
|
||||
throw CustomerSearchException(error.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user