Skip to content

Commit

Permalink
resolved conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
naveen-egov committed Oct 5, 2023
2 parents 91a52bd + eb2a243 commit f5c4b2b
Show file tree
Hide file tree
Showing 34 changed files with 1,660 additions and 398 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Flutter action
uses: subosito/[email protected]
with:
flutter-version: '3.10.5'
flutter-version: "3.10.5"

- name: Generate models
run: ./tools/install_bricks.sh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:stream_transform/stream_transform.dart';

import '../../data/repositories/local/address.dart';
import '../../data/repositories/local/project_beneficiary.dart';
import '../../data/repositories/local/task.dart';
import '../../models/data_model.dart';
Expand All @@ -26,6 +27,7 @@ class SearchHouseholdsBloc
final String userUid;
final IndividualDataRepository individual;
final HouseholdDataRepository household;
final AddressLocalRepository addressRepository;
final HouseholdMemberDataRepository householdMember;
final ProjectBeneficiaryDataRepository projectBeneficiary;
final TaskDataRepository taskDataRepository;
Expand All @@ -39,13 +41,15 @@ class SearchHouseholdsBloc
required this.projectBeneficiary,
required this.taskDataRepository,
required this.beneficiaryType,
required this.addressRepository,
}) : super(const SearchHouseholdsState()) {
on(
_handleSearchByHouseholdHead,
transformer: debounce<SearchHouseholdsSearchByHouseholdHeadEvent>(
const Duration(milliseconds: 100),
),
);
on(_handleSearchByProximitity);
on(_handleClear);
on(_handleSearchByHousehold);
on(_handleInitialize);
Expand Down Expand Up @@ -193,6 +197,85 @@ class SearchHouseholdsBloc
}
}

FutureOr<void> _handleSearchByProximitity(
SearchHouseholdsByProximityEvent event,
SearchHouseholdsEmitter emit,
) async {
emit(state.copyWith(loading: true));
final results =
await addressRepository.searchHouseHoldbyAddress(AddressSearchModel(
latitude: event.latitude,
longitude: event.longititude,
maxRadius: event.maxRadius,
));
final containers = <HouseholdMemberWrapper>[];
for (final element in results) {
final members = await householdMember.search(
HouseholdMemberSearchModel(
householdClientReferenceId: element.clientReferenceId,
),
);
final head = await householdMember.search(
HouseholdMemberSearchModel(
householdClientReferenceId: element.clientReferenceId,
isHeadOfHousehold: true,
),
);

final individualIds = members
.map((element) => element.individualClientReferenceId)
.whereNotNull()
.toList();

final allHouseholdMembers = await individual.search(
IndividualSearchModel(
clientReferenceId: individualIds,
),
);

final headOfHousehold = allHouseholdMembers.firstWhere((element) =>
element.clientReferenceId == head.first.individualClientReferenceId);

final projectBeneficiaries = beneficiaryType != BeneficiaryType.individual
? await projectBeneficiary.search(
ProjectBeneficiarySearchModel(
beneficiaryClientReferenceId: [element.clientReferenceId],
//[TODO] Need to check for beneficiaryId
projectId: event.projectId,
),
)
: await projectBeneficiary.search(
ProjectBeneficiarySearchModel(
beneficiaryClientReferenceId: individualIds,
//[TODO] Need to check for beneficiaryId
projectId: event.projectId,
),
);

final tasks = await taskDataRepository.search(TaskSearchModel(
projectBeneficiaryClientReferenceId:
projectBeneficiaries.map((e) => e.clientReferenceId).toList(),
));

containers.add(
HouseholdMemberWrapper(
household: element,
headOfHousehold: headOfHousehold,
members: allHouseholdMembers,
projectBeneficiaries: projectBeneficiaries,
tasks: tasks.isEmpty ? null : tasks,
),
);
}
emit(state.copyWith(
householdMembers: containers,
loading: false,
searchQuery: null,
));

return;
}

FutureOr<void> _handleSearchByHouseholdHead(
SearchHouseholdsSearchByHouseholdHeadEvent event,
SearchHouseholdsEmitter emit,
Expand All @@ -211,21 +294,36 @@ class SearchHouseholdsBloc
searchQuery: event.searchText,
));

final results = await individual.search(
final List<HouseholdModel> proximityBasedResults =
await addressRepository.searchHouseHoldbyAddress(AddressSearchModel(
latitude: event.latitude,
longitude: event.longitude,
maxRadius: event.maxRadius,
));
final List<IndividualModel> results = await individual.search(
IndividualSearchModel(
name: NameSearchModel(givenName: event.searchText.trim()),
),
);

final householdMembers = <HouseholdMemberModel>[];

for (final element in results) {
final members = await householdMember.search(
HouseholdMemberSearchModel(
individualClientReferenceId: element.clientReferenceId,
isHeadOfHousehold: true,
),
);
final r = event.isProximityEnabled ? proximityBasedResults : results;
for (final element in r) {
final members = event.isProximityEnabled
? await householdMember.search(
HouseholdMemberSearchModel(
householdClientReferenceId:
(element as HouseholdModel).clientReferenceId,
isHeadOfHousehold: true,
),
)
: await householdMember.search(
HouseholdMemberSearchModel(
individualClientReferenceId:
(element as IndividualModel).clientReferenceId,
isHeadOfHousehold: true,
),
);

for (final member in members) {
final allHouseholdMembers = await householdMember.search(
Expand All @@ -250,20 +348,31 @@ class SearchHouseholdsBloc
.toList();

if (householdId == null) continue;

final households = await household.search(
HouseholdSearchModel(
clientReferenceId: [householdId],
latitude: event.latitude,
longitude: event.longitude,
maxRadius: event.maxRadius,
),
);

if (households.isEmpty) continue;

final resultHousehold = households.first;

final individuals = await individual.search(
IndividualSearchModel(clientReferenceId: individualIds),
);
final individuals = event.isProximityEnabled
? await individual.search(
IndividualSearchModel(
clientReferenceId: individualIds,
name: NameSearchModel(givenName: event.searchText.trim()),
),
)
: await individual.search(
IndividualSearchModel(
clientReferenceId: individualIds,
),
);

final head = individuals.firstWhereOrNull(
(element) =>
Expand Down Expand Up @@ -336,14 +445,29 @@ class SearchHouseholdsEvent with _$SearchHouseholdsEvent {

const factory SearchHouseholdsEvent.searchByHousehold({
required String projectId,
double? latitude,
double? longitude,
double? maxRadius,
required final bool isProximityEnabled,
required HouseholdModel householdModel,
}) = SearchHouseholdsByHouseholdsEvent;

const factory SearchHouseholdsEvent.searchByHouseholdHead({
required String searchText,
required String projectId,
required final bool isProximityEnabled,
double? latitude,
double? longitude,
double? maxRadius,
}) = SearchHouseholdsSearchByHouseholdHeadEvent;

const factory SearchHouseholdsEvent.searchByProximity({
required double latitude,
required double longititude,
required String projectId,
required double maxRadius,
}) = SearchHouseholdsByProximityEvent;

const factory SearchHouseholdsEvent.clear() = SearchHouseholdsClearEvent;
}

Expand Down Expand Up @@ -374,6 +498,7 @@ class HouseholdMemberWrapper with _$HouseholdMemberWrapper {
required IndividualModel headOfHousehold,
required List<IndividualModel> members,
required List<ProjectBeneficiaryModel> projectBeneficiaries,
double? distance,
List<TaskModel>? tasks,
}) = _HouseholdMemberWrapper;
}
Loading

0 comments on commit f5c4b2b

Please sign in to comment.