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.
		
		
		
		
		
			
		
			
				
	
	
		
			52 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Dart
		
	
			
		
		
	
	
			52 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Dart
		
	
import 'dart:convert';
 | 
						|
import 'dart:io';
 | 
						|
 | 
						|
import 'package:car_customer_app/models/account.dart';
 | 
						|
import 'package:car_customer_app/models/response_models.dart';
 | 
						|
import 'package:car_customer_app/services/backend_service.dart';
 | 
						|
import 'package:injector/injector.dart';
 | 
						|
 | 
						|
 | 
						|
 | 
						|
abstract class IAcRepository {
 | 
						|
  Future<Account> getAccountList();
 | 
						|
 | 
						|
  Future<BackendResponse> 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<Account> getAccountList() async {
 | 
						|
    BackendResponse response = await Injector.appInstance
 | 
						|
        .getDependency<IBackendApiService>()
 | 
						|
        .getAuthenticatedAPI(ACCOUNT_LIST);
 | 
						|
 | 
						|
    if (response != null && response.isOk) {
 | 
						|
      return Account.fromJson(response.result);
 | 
						|
    } else {
 | 
						|
      throw Exception();
 | 
						|
    }
 | 
						|
  }
 | 
						|
 | 
						|
  @override
 | 
						|
  Future<BackendResponse> updateAccount(String dataAsJson) async {
 | 
						|
    BackendResponse response = await Injector.appInstance
 | 
						|
        .getDependency<IBackendApiService>()
 | 
						|
        .postAuthenticatedAPI(UPDATE_LIST, dataAsJson);
 | 
						|
 | 
						|
    if (response != null && response.isOk) {
 | 
						|
      //if parsing failed, throw exception
 | 
						|
      return response;
 | 
						|
    } else {
 | 
						|
      throw Exception();
 | 
						|
    }
 | 
						|
  }
 | 
						|
}
 |