Skip to content

Commit

Permalink
code rabbit comments resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
naveenr-egov committed Dec 18, 2024
1 parent ebf8835 commit 7ed52ed
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ class LocalizationLocalRepository {

FutureOr create(
List<LocalizationCompanion> result, LocalSqlDataStore sql) async {
if (result.isEmpty) return;
return retryLocalCallOperation(() async {
return sql.batch((batch) {
batch.insertAll(sql.localization, result);
batch.insertAllOnConflictUpdate(sql.localization, result);
});
});
}
Expand Down
149 changes: 83 additions & 66 deletions apps/health_campaign_field_worker_app/lib/data/sync_registry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:complaints/models/pgr_complaints.dart';
import 'package:complaints/models/pgr_complaints_response.dart';
import 'package:digit_components/utils/app_logger.dart';
import 'package:digit_data_model/data_model.dart';
import 'package:flutter/cupertino.dart';
import 'package:sync_service/data/repositories/sync/sync_up.dart';

class CustomSyncRegistry implements SyncUpOperation {
Expand All @@ -12,17 +13,29 @@ class CustomSyncRegistry implements SyncUpOperation {

@override
Future<void> update(List<EntityModel> entities, LocalRepository local) async {
await remote.bulkUpdate(entities);
try {
await remote.bulkUpdate(entities);
} catch (e) {
debugPrint('$e');
}
}

@override
Future<void> delete(List<EntityModel> entities, LocalRepository local) async {
await remote.bulkDelete(entities);
try {
await remote.bulkDelete(entities);
} catch (e) {
debugPrint('$e');
}
}

@override
Future<void> singleCreate(EntityModel entity, LocalRepository local) async {
await remote.singleCreate(entity);
try {
await remote.singleCreate(entity);
} catch (e) {
debugPrint('$e');
}
}

@override
Expand All @@ -34,76 +47,80 @@ class CustomSyncRegistry implements SyncUpOperation {
operationGroupedEntity,
required MapEntry<DataModelType, List<OpLogEntry<EntityModel>>>
typeGroupedEntity}) async {
switch (typeGroupedEntity.key) {
case DataModelType.complaints:
for (final entity in entities) {
if (remote is PgrServiceRemoteRepository &&
entity is PgrServiceModel) {
final response = await remote.create(entity);
final responseData = response.data;
if (responseData is! Map<String, dynamic>) {
AppLogger.instance.error(
title: 'NetworkManager : PgrServiceRemoteRepository',
message: responseData,
stackTrace: StackTrace.current,
);
continue;
}
try {
switch (typeGroupedEntity.key) {
case DataModelType.complaints:
for (final entity in entities) {
if (remote is PgrServiceRemoteRepository &&
entity is PgrServiceModel) {
final response = await remote.create(entity);
final responseData = response.data;
if (responseData is! Map<String, dynamic>) {
AppLogger.instance.error(
title: 'NetworkManager : PgrServiceRemoteRepository',
message: responseData,
stackTrace: StackTrace.current,
);
continue;
}

PgrServiceCreateResponseModel pgrServiceCreateResponseModel;
PgrComplaintResponseModel pgrComplaintModel;
try {
pgrServiceCreateResponseModel =
PgrServiceCreateResponseModelMapper.fromMap(
responseData,
);
pgrComplaintModel =
pgrServiceCreateResponseModel.serviceWrappers.first;
} catch (e) {
rethrow;
}
PgrServiceCreateResponseModel pgrServiceCreateResponseModel;
PgrComplaintResponseModel pgrComplaintModel;
try {
pgrServiceCreateResponseModel =
PgrServiceCreateResponseModelMapper.fromMap(
responseData,
);
pgrComplaintModel =
pgrServiceCreateResponseModel.serviceWrappers.first;
} catch (e) {
rethrow;
}

final service = pgrComplaintModel.service;
final serviceRequestId = service.serviceRequestId;
final service = pgrComplaintModel.service;
final serviceRequestId = service.serviceRequestId;

if (serviceRequestId == null || serviceRequestId.isEmpty) {
AppLogger.instance.error(
title: 'NetworkManager : PgrServiceRemoteRepository',
message: 'Service Request ID is null',
stackTrace: StackTrace.current,
);
continue;
}

await local.markSyncedUp(
entry: entry.firstWhere((element) =>
element.clientReferenceId == entity.clientReferenceId),
clientReferenceId: entity.clientReferenceId,
nonRecoverableError: entity.nonRecoverableError,
);
if (serviceRequestId == null || serviceRequestId.isEmpty) {
AppLogger.instance.error(
title: 'NetworkManager : PgrServiceRemoteRepository',
message: 'Service Request ID is null',
stackTrace: StackTrace.current,
);
continue;
}

await local.opLogManager.updateServerGeneratedIds(
model: UpdateServerGeneratedIdModel(
await local.markSyncedUp(
entry: entry.firstWhere((element) =>
element.clientReferenceId == entity.clientReferenceId),
clientReferenceId: entity.clientReferenceId,
serverGeneratedId: serviceRequestId,
dataOperation: operationGroupedEntity.key,
rowVersion: entity.rowVersion,
),
);
nonRecoverableError: entity.nonRecoverableError,
);

await local.update(
entity.copyWith(
serviceRequestId: serviceRequestId,
id: service.id,
applicationStatus: service.applicationStatus,
accountId: service.accountId,
),
createOpLog: false,
);
await local.opLogManager.updateServerGeneratedIds(
model: UpdateServerGeneratedIdModel(
clientReferenceId: entity.clientReferenceId,
serverGeneratedId: serviceRequestId,
dataOperation: operationGroupedEntity.key,
rowVersion: entity.rowVersion,
),
);

await local.update(
entity.copyWith(
serviceRequestId: serviceRequestId,
id: service.id,
applicationStatus: service.applicationStatus,
accountId: service.accountId,
),
createOpLog: false,
);
}
}
}
default:
await remote.bulkCreate(entities);
default:
await remote.bulkCreate(entities);
}
} catch (e) {
debugPrint('$e');
}
}

Expand Down
2 changes: 1 addition & 1 deletion apps/health_campaign_field_worker_app/lib/pages/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class _LoginPageState extends LocalizedState<LoginPage> {
),
_password: FormControl<String>(
validators: [Validators.required],
value: 'eGov@123',
value: '',
),
_privacyCheck: FormControl<bool>(
value: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import 'package:referral_reconciliation/blocs/app_localization.dart'
as referral_reconciliation_localization;
import 'package:registration_delivery/blocs/app_localization.dart'
as registration_delivery_localization;
import 'package:digit_components/blocs/localization.dart' as component_localization;
import 'package:survey_form/blocs/app_localization.dart'
as survey_form_localization;

Expand Down
2 changes: 1 addition & 1 deletion apps/health_campaign_field_worker_app/lib/utils/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ performBackgroundService({

if (stopService) {
if (isRunning) {
if (!isBackground && context != null) {
if (!isBackground && context != null && context.mounted) {
if (context.mounted) {
DigitToast.show(
context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,9 @@ import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:inventory_management/inventory_management.dart';
import 'package:inventory_management/inventory_management.dart';
import 'package:inventory_management/inventory_management.dart';
import 'package:isar/isar.dart';
import 'package:provider/provider.dart';
import 'package:referral_reconciliation/referral_reconciliation.dart';
import 'package:referral_reconciliation/referral_reconciliation.dart';
import 'package:referral_reconciliation/referral_reconciliation.dart';
import 'package:registration_delivery/registration_delivery.dart';
import 'package:registration_delivery/registration_delivery.dart';
import 'package:registration_delivery/registration_delivery.dart';
import 'package:survey_form/survey_form.dart';

Expand Down

0 comments on commit 7ed52ed

Please sign in to comment.