43 lines
1.3 KiB
Dart
43 lines
1.3 KiB
Dart
import 'package:fotodocumentation/controller/base_controller.dart';
|
|
import 'package:fotodocumentation/dto/customer_dto.dart';
|
|
|
|
abstract interface class CustomerController {
|
|
Future<List<CustomerListDto>> getAll(String query, String startsWith);
|
|
|
|
Future<CustomerDto?> get({required int id});
|
|
|
|
Future<List<int>> export({required int customerId, int? pictureId});
|
|
}
|
|
|
|
class CustomerControllerImpl extends BaseController implements CustomerController {
|
|
final String path = "customer";
|
|
|
|
@override
|
|
Future<List<CustomerListDto>> getAll(String query, String startsWith) async {
|
|
String uriStr = '${uriUtils.getBaseUrl()}$path?query=$query&startsWith=$startsWith';
|
|
return runGetListWithAuth(uriStr, (p0) {
|
|
List<CustomerListDto> retVal = [];
|
|
for (var elem in p0) {
|
|
var entity = CustomerListDto.fromJson(elem);
|
|
retVal.add(entity);
|
|
}
|
|
return retVal;
|
|
});
|
|
}
|
|
|
|
@override
|
|
Future<CustomerDto?> get({required int id}) {
|
|
String uriStr = '${uriUtils.getBaseUrl()}$path/$id';
|
|
return runGetWithAuth(uriStr, (json) => CustomerDto.fromJson(json));
|
|
}
|
|
|
|
@override
|
|
Future<List<int>> export({required int customerId, int? pictureId}) {
|
|
String uriStr = '${uriUtils.getBaseUrl()}$path/export/$customerId';
|
|
if (pictureId != null) {
|
|
uriStr += '?picture=$pictureId';
|
|
}
|
|
return runGetBytesWithAuth(uriStr);
|
|
}
|
|
}
|