import 'dart:convert'; import 'dart:io'; import 'package:mohem_flutter_app/models/account.dart'; import 'package:mohem_flutter_app/models/response_models.dart'; import 'package:mohem_flutter_app/services/backend_service.dart'; import 'package:injector/injector.dart'; abstract class IAcRepository { Future getAccountList(); Future updateAccount(String dataAsJson); } class AcRepository implements IAcRepository { static const String ACCOUNT_API_CONTROLLER_MOBILE = "AccountApiControllerMobile/"; static const String ACCOUNT_LIST = ACCOUNT_API_CONTROLLER_MOBILE + "list"; static const String UPDATE_LIST = ACCOUNT_API_CONTROLLER_MOBILE + "saveaccountselected"; @override Future getAccountList() async { BackendResponse response = await Injector.appInstance .getDependency() .getAuthenticatedAPI(ACCOUNT_LIST); if (response != null && response.isOk) { return Account.fromJson(response.result); } else { throw Exception(); } } @override Future updateAccount(String dataAsJson) async { BackendResponse response = await Injector.appInstance .getDependency() .postAuthenticatedAPI(UPDATE_LIST, dataAsJson); if (response != null && response.isOk) { //if parsing failed, throw exception return response; } else { throw Exception(); } } }