feat: Refactor code structure and optimize performance across multiple modules
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:krow/core/application/clients/api/api_client.dart';
|
||||
import 'package:krow/core/data/models/staff/bank_acc.dart';
|
||||
import 'package:krow/features/profile/bank_account/data/gql.dart';
|
||||
|
||||
@injectable
|
||||
class BankAccountApiProvider {
|
||||
final ApiClient _apiClient;
|
||||
|
||||
BankAccountApiProvider(this._apiClient);
|
||||
|
||||
Stream<BankAcc?> getStaffBankAcc() async* {
|
||||
await for (var response
|
||||
in _apiClient.queryWithCache(schema: staffBankAccount)) {
|
||||
if (response == null || response.data == null) {
|
||||
continue;
|
||||
}
|
||||
if (response.hasException) {
|
||||
throw Exception(response.exception.toString());
|
||||
}
|
||||
final bankAcc =
|
||||
BankAcc.fromJson(response.data?['me']?['bank_account'] ?? {});
|
||||
yield bankAcc;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> putBunkAccount(BankAcc bankAcc) async {
|
||||
final Map<String, dynamic> variables = {
|
||||
'input': bankAcc.toJson(),
|
||||
};
|
||||
|
||||
var result =
|
||||
await _apiClient.mutate(schema: updateBankAccount, body: variables);
|
||||
|
||||
if (result.hasException) {
|
||||
throw Exception(result.exception.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import 'package:krow/core/data/models/staff/bank_acc.dart';
|
||||
|
||||
abstract class BankAccountRepository {
|
||||
Stream<BankAcc?> getStaffBankAcc();
|
||||
|
||||
Future<void> putBankAcc(BankAcc address);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
const String staffBankAccount = r'''
|
||||
query staffAddress {
|
||||
me {
|
||||
id
|
||||
bank_account {
|
||||
id
|
||||
holder_name
|
||||
bank_name
|
||||
number
|
||||
routing_number
|
||||
country
|
||||
state
|
||||
city
|
||||
street
|
||||
building
|
||||
zip
|
||||
}
|
||||
}
|
||||
}
|
||||
''';
|
||||
|
||||
const String updateBankAccount = r'''
|
||||
mutation updateBankAccount($input: UpdateStaffBankAccountInput!) {
|
||||
update_staff_bank_account(input: $input) {
|
||||
|
||||
}
|
||||
}
|
||||
''';
|
||||
Reference in New Issue
Block a user