feat: legacy mobile apps created
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:krow/core/application/clients/api/api_client.dart';
|
||||
import 'package:krow/core/data/models/staff/full_address_model.dart';
|
||||
import 'package:krow/features/profile/address/data/gql.dart';
|
||||
|
||||
@injectable
|
||||
class AddressApiProvider {
|
||||
final ApiClient _apiClient;
|
||||
|
||||
AddressApiProvider(this._apiClient);
|
||||
|
||||
Stream<FullAddress?> getStaffAddress() async* {
|
||||
await for (var response
|
||||
in _apiClient.queryWithCache(schema: staffAddress)) {
|
||||
if (response == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (response.hasException) {
|
||||
throw Exception(response.exception.toString());
|
||||
}
|
||||
|
||||
final address =
|
||||
FullAddress.fromJson(response.data?['me']?['full_address'] ?? {});
|
||||
yield address;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> putAddress(FullAddress address) async {
|
||||
final Map<String, dynamic> variables = {
|
||||
'input': address.toJson(),
|
||||
};
|
||||
|
||||
var result =
|
||||
await _apiClient.mutate(schema: saveFullAddress, body: variables);
|
||||
|
||||
if (result.hasException) {
|
||||
throw Exception(result.exception.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import 'package:krow/core/data/models/staff/full_address_model.dart';
|
||||
|
||||
abstract class AddressRepository {
|
||||
Stream<FullAddress?> getStaffAddress();
|
||||
|
||||
Future<void> putAddress(FullAddress address);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
const String staffAddress = r'''
|
||||
query staffAddress {
|
||||
me {
|
||||
id
|
||||
full_address {
|
||||
street_number
|
||||
zip_code
|
||||
latitude
|
||||
longitude
|
||||
formatted_address
|
||||
street
|
||||
region
|
||||
city
|
||||
country
|
||||
}
|
||||
}
|
||||
}
|
||||
''';
|
||||
|
||||
const String saveFullAddress = r'''
|
||||
mutation saveFullAddress($input: AddressInput!) {
|
||||
update_staff_address(input: $input) {
|
||||
|
||||
}
|
||||
}
|
||||
''';
|
||||
Reference in New Issue
Block a user