feat: legacy mobile apps created
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
const String getStaffMobilityInfoSchema = '''
|
||||
query GetPersonalInfo {
|
||||
me {
|
||||
id
|
||||
accessibility {
|
||||
has_car
|
||||
can_relocate
|
||||
requires_accommodations
|
||||
accommodation_details
|
||||
}
|
||||
}
|
||||
}
|
||||
''';
|
||||
|
||||
const String updateStaffMobilityMutationSchema = '''
|
||||
mutation UpdateStaffAccessibilityInfo(\$input: UpdateStaffAccessibilitiesInput!) {
|
||||
update_staff_accessibilities(input: \$input) {
|
||||
accessibility {
|
||||
has_car
|
||||
can_relocate
|
||||
}
|
||||
}
|
||||
}
|
||||
''';
|
||||
@@ -0,0 +1,26 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
@immutable
|
||||
class MobilityModel {
|
||||
const MobilityModel({
|
||||
required this.hasACar,
|
||||
required this.canRelocate,
|
||||
});
|
||||
|
||||
factory MobilityModel.fromJson(Map<String, dynamic> json) {
|
||||
return MobilityModel(
|
||||
hasACar: json['has_car'] as bool? ?? false,
|
||||
canRelocate: json['can_relocate'] as bool? ?? false,
|
||||
);
|
||||
}
|
||||
|
||||
final bool hasACar;
|
||||
final bool canRelocate;
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'has_car': hasACar,
|
||||
'can_relocate': canRelocate,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:krow/core/application/clients/api/api_client.dart';
|
||||
import 'package:krow/features/profile/mobility/data/gql_shemas.dart';
|
||||
import 'package:krow/features/profile/mobility/data/models/mobility_model.dart';
|
||||
|
||||
@injectable
|
||||
class StaffMobilityApiProvider {
|
||||
StaffMobilityApiProvider(this._client);
|
||||
|
||||
final ApiClient _client;
|
||||
|
||||
Stream<MobilityModel> getStaffMobilityWithCache() async* {
|
||||
await for (var response in _client.queryWithCache(
|
||||
schema: getStaffMobilityInfoSchema,
|
||||
)) {
|
||||
if (response == null || response.data == null) continue;
|
||||
|
||||
if (response.hasException) {
|
||||
throw Exception(response.exception.toString());
|
||||
}
|
||||
|
||||
try {
|
||||
yield MobilityModel.fromJson(
|
||||
(response.data?['me'] as Map<String, dynamic>?)?['accessibility'] ??
|
||||
{},
|
||||
);
|
||||
} catch (except) {
|
||||
log(
|
||||
'Exception in StaffMobilityApiProvider '
|
||||
'on getStaffMobilityWithCache()',
|
||||
error: except,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<MobilityModel?> updateStaffMobilityInfo(MobilityModel data) async {
|
||||
var result = await _client.mutate(
|
||||
schema: updateStaffMobilityMutationSchema,
|
||||
body: {
|
||||
'input': data.toJson(),
|
||||
},
|
||||
);
|
||||
|
||||
if (result.hasException) {
|
||||
throw Exception(result.exception.toString());
|
||||
}
|
||||
|
||||
if (result.data == null || result.data!.isEmpty) return null;
|
||||
|
||||
return MobilityModel.fromJson(
|
||||
(result.data?['update_staff_accessibilities']
|
||||
as Map<String, dynamic>?)?['accessibility'] ??
|
||||
{},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import 'package:krow/features/profile/mobility/data/models/mobility_model.dart';
|
||||
|
||||
abstract class StaffMobilityRepository {
|
||||
Stream<MobilityModel> getStaffMobility();
|
||||
|
||||
Future<MobilityModel?> updateStaffMobilityInfo(
|
||||
MobilityModel data,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user