Skip to content

Commit

Permalink
Minor improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-radhika-s committed Dec 24, 2024
1 parent 90a01ef commit d11d73c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 32 deletions.
42 changes: 17 additions & 25 deletions data/lib/repository/geofence_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 0 additions & 7 deletions data/lib/service/place_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@ class PlaceService {
return querySnapshot.docs.firstOrNull?.data() as ApiPlace?;
}

Future<List<ApiPlace>> getAllPlace(String spaceId) async {
final snapshot = await spacePlacesRef(spaceId).get();
return snapshot.docs
.map((doc) => ApiPlace.fromJson(doc.data() as Map<String, dynamic>))
.toList();
}

Future<void> deletePlace(String spaceId, String placeId) async {
await spacePlacesRef(spaceId).doc(placeId).delete();
}
Expand Down

0 comments on commit d11d73c

Please sign in to comment.