From d11d73c5e3abfc15f3d8eeb951bfaafdf3f67bc4 Mon Sep 17 00:00:00 2001 From: Radhika Canopas Date: Tue, 24 Dec 2024 15:34:25 +0530 Subject: [PATCH] Minor improvement --- data/lib/repository/geofence_repository.dart | 42 ++++++++------------ data/lib/service/place_service.dart | 7 ---- 2 files changed, 17 insertions(+), 32 deletions(-) diff --git a/data/lib/repository/geofence_repository.dart b/data/lib/repository/geofence_repository.dart index cad20f9c..a349e8cc 100644 --- a/data/lib/repository/geofence_repository.dart +++ b/data/lib/repository/geofence_repository.dart @@ -26,31 +26,23 @@ class GeofenceRepository { void makeHttpCall(String placeId, int status) async { try { - final spaces = await spaceService.getUserSpaces(_currentUser?.id ?? ''); - for (final space in spaces) { - final spaceId = space!.id; - final places = await placeService.getAllPlace(spaceId); - - for (final place in places) { - if (place.id == placeId) { - final message = status == GEOFENCE_ENTER - ? '${_currentUser?.first_name ?? ''} has arrived at 📍${place.name}' - : '${_currentUser?.first_name ?? ''} has left 📍${place.name}'; - - final data = { - 'placeId': placeId, - 'spaceId': place.space_id, - 'eventBy': _currentUser?.id ?? '', - 'message': message, - 'eventType': status == GEOFENCE_ENTER ? "1" : "2", - }; - - final callable = - FirebaseFunctions.instanceFor(region: 'asia-south1') - .httpsCallable('sendGeoFenceNotification'); - await callable.call(data); - } - } + final place = await placeService.getPlace(placeId); + if (place != null) { + final message = status == GEOFENCE_ENTER + ? '${_currentUser?.first_name ?? ''} has arrived at 📍${place.name}' + : '${_currentUser?.first_name ?? ''} has left 📍${place.name}'; + + final data = { + 'placeId': placeId, + 'spaceId': place.space_id, + 'eventBy': _currentUser?.id ?? '', + 'message': message, + 'eventType': status == GEOFENCE_ENTER ? "1" : "2", + }; + + final callable = FirebaseFunctions.instanceFor(region: 'asia-south1') + .httpsCallable('sendGeoFenceNotification'); + await callable.call(data); } } catch (error, stack) { logger.e( diff --git a/data/lib/service/place_service.dart b/data/lib/service/place_service.dart index a84a3bac..28a3f62d 100644 --- a/data/lib/service/place_service.dart +++ b/data/lib/service/place_service.dart @@ -57,13 +57,6 @@ class PlaceService { return querySnapshot.docs.firstOrNull?.data() as ApiPlace?; } - Future> getAllPlace(String spaceId) async { - final snapshot = await spacePlacesRef(spaceId).get(); - return snapshot.docs - .map((doc) => ApiPlace.fromJson(doc.data() as Map)) - .toList(); - } - Future deletePlace(String spaceId, String placeId) async { await spacePlacesRef(spaceId).doc(placeId).delete(); }