You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
2.2 KiB
Dart
64 lines
2.2 KiB
Dart
import 'package:test_sa/api/devices_api_client.dart';
|
|
import 'package:test_sa/controllers/providers/loading_notifier.dart';
|
|
|
|
import '../../../models/device/device.dart';
|
|
|
|
class DevicesProvider extends LoadingNotifier {
|
|
final List<Device> _searchableList = [];
|
|
|
|
List<Device> get searchableList => _searchableList;
|
|
|
|
//reset provider data
|
|
void reset() {
|
|
DevicesApiClient().devices.clear();
|
|
_stateCode = null;
|
|
}
|
|
|
|
// state code of current request to defied error message
|
|
// like 400 customer request failed
|
|
// 500 service not available
|
|
int? _stateCode;
|
|
|
|
int? get stateCode => _stateCode;
|
|
|
|
/// - Fetching Devices From The Server and Inserting them into [DevicesApiClient.devices] List.
|
|
/// - [_searchableList] will be filled after the request succeed.
|
|
///
|
|
/// ### NOTE : if [hospitalId] is [NULL] nothing will happen
|
|
Future getEquipment({required String? hospitalId}) async {
|
|
if (hospitalId != null) {
|
|
_searchableList.clear();
|
|
waitApiRequest(
|
|
() async {
|
|
await DevicesApiClient().getEquipment(hospitalId);
|
|
_searchableList.addAll(DevicesApiClient().devices);
|
|
},
|
|
onSuccess: () {
|
|
/// TODO : this is temporary
|
|
_stateCode = 200;
|
|
},
|
|
onError: (error) {
|
|
/// TODO : this is temporary
|
|
_stateCode = error.error?.errorCode;
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Returns a list of devices by [hospitalId] and [serialNumber] (or | and) [number]
|
|
///
|
|
/// ### NOTE : if [hospitalId] is [NULL] empty list will be returned
|
|
Future<List<Device>> getDevicesList({required String? hospitalId, String? serialNumber, String? number}) {
|
|
if (hospitalId == null) return Future.value(const []);
|
|
return DevicesApiClient().getDevicesList(hospitalId: hospitalId, serialNumber: serialNumber, number: number);
|
|
}
|
|
|
|
/// Returns a list of devices by [hospitalId] (and optionally) [serialNumber]
|
|
///
|
|
/// ### NOTE : if [hospitalId] is [NULL] empty list will be returned
|
|
Future<List<Device>> getDevicesListBySN({required String? hospitalId, required String serialNumber}) {
|
|
if (hospitalId == null) return Future.value(const []);
|
|
return DevicesApiClient().getDevicesListBySN(hospitalId: hospitalId, serialNumber: serialNumber);
|
|
}
|
|
}
|