feat: Refactor code structure and optimize performance across multiple modules
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import 'package:graphql_flutter/graphql_flutter.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:krow/core/application/clients/api/api_client.dart';
|
||||
import 'package:krow/core/application/clients/api/api_exception.dart';
|
||||
import 'package:krow/features/clock_manual/data/clock_manual_gql.dart';
|
||||
|
||||
@singleton
|
||||
class ClockManualApiProvider {
|
||||
final ApiClient _client;
|
||||
|
||||
ClockManualApiProvider({required ApiClient client}) : _client = client;
|
||||
|
||||
Future<void> trackClientClockin(String positionStaffId) async {
|
||||
final QueryResult result = await _client.mutate(
|
||||
schema: trackClientClockinMutation,
|
||||
body: {'position_staff_id': positionStaffId},
|
||||
);
|
||||
if (result.hasException) {
|
||||
throw parseBackendError(result.exception!);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> trackClientClockout(String positionStaffId) async {
|
||||
final QueryResult result = await _client.mutate(
|
||||
schema: trackClientClockoutMutation,
|
||||
body: {'position_staff_id': positionStaffId},
|
||||
);
|
||||
if (result.hasException) {
|
||||
throw parseBackendError(result.exception!);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> cancelClockin(String positionStaffId) async {
|
||||
final QueryResult result = await _client.mutate(
|
||||
schema: cancelClockinMutation,
|
||||
body: {'position_staff_id': positionStaffId},
|
||||
);
|
||||
if (result.hasException) {
|
||||
throw parseBackendError(result.exception!);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
const String trackClientClockinMutation = r'''
|
||||
mutation track_client_clockin($position_staff_id: ID!) {
|
||||
track_client_clockin(position_staff_id: $position_staff_id) {
|
||||
id
|
||||
}
|
||||
}
|
||||
''';
|
||||
|
||||
const String trackClientClockoutMutation = r'''
|
||||
mutation track_client_clockout($position_staff_id: ID!) {
|
||||
track_client_clockout(position_staff_id: $position_staff_id) {
|
||||
id
|
||||
}
|
||||
}
|
||||
''';
|
||||
|
||||
const String cancelClockinMutation = r'''
|
||||
mutation cancel_client_clockin($position_staff_id: ID!) {
|
||||
cancel_client_clockin(position_staff_id: $position_staff_id) {
|
||||
id
|
||||
}
|
||||
}
|
||||
''';
|
||||
@@ -0,0 +1,43 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:krow/features/clock_manual/data/clock_manual_api_provider.dart';
|
||||
import 'package:krow/features/clock_manual/domain/clock_manual_repository.dart';
|
||||
|
||||
@Singleton(as: ClockManualRepository)
|
||||
class ClockManualRepositoryImpl implements ClockManualRepository {
|
||||
final ClockManualApiProvider apiProvider;
|
||||
|
||||
ClockManualRepositoryImpl({required this.apiProvider});
|
||||
|
||||
@override
|
||||
Future<void> trackClientClockin(String positionStaffId) async {
|
||||
try {
|
||||
await apiProvider.trackClientClockin(positionStaffId);
|
||||
} catch (exception) {
|
||||
debugPrint(exception.toString());
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> trackClientClockout(String positionStaffId) async {
|
||||
try {
|
||||
await apiProvider.trackClientClockout(positionStaffId);
|
||||
} catch (exception) {
|
||||
debugPrint(exception.toString());
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> cancelClockin(String positionStaffId) async{
|
||||
try {
|
||||
await apiProvider.cancelClockin(positionStaffId);
|
||||
} catch (exception) {
|
||||
debugPrint(exception.toString());
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user