From 480f3991e18eef12f9611cb2c11ae23b5b8c478e Mon Sep 17 00:00:00 2001 From: Nicole Qiu Date: Wed, 29 Oct 2025 15:32:36 -0400 Subject: [PATCH 1/3] debuggggg --- src/schema.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/schema.py b/src/schema.py index bdfeb2d..4bdffd7 100644 --- a/src/schema.py +++ b/src/schema.py @@ -29,6 +29,7 @@ import json import os from firebase_admin import messaging +import logging # MARK: - Gym @@ -919,8 +920,19 @@ def mutate(self, info, reminder_id, new_gyms, days_of_week, new_capacity_thresho for topic in topics: try: response = messaging.unsubscribe_from_topic(reminder.fcm_token, topic) + logging.info( + "Unsubscribe %s from %s -> success: %d failure: %d", + reminder.fcm_token[:12], + topic, + response.success_count, + response.failure_count, + ) + for error in response.errors: + logging.warning( + "Error unsubscribing %s from %s -> reason: %s", reminder.fcm_token[:12], topic, error.reason + ) if response.success_count == 0: - raise Exception(response.errors[0].reason) + raise Exception(response.errors[0].reason) except Exception as error: raise GraphQLError(f"Error subscribing to topic: {error}") @@ -930,8 +942,15 @@ def mutate(self, info, reminder_id, new_gyms, days_of_week, new_capacity_thresho for topic in topics: try: response = messaging.subscribe_to_topic(reminder.fcm_token, topic) + logging.info( + "Resubscribing %s to %s -> success: %d failure: %d", + reminder.fcm_token[:12], + topic, + response.success_count, + response.failure_count, + ) if response.success_count == 0: - raise Exception(response.errors[0].reason) + raise Exception(response.errors[0].reason) except Exception as error: raise GraphQLError(f"Error subscribing to topic: {error}") @@ -961,6 +980,13 @@ def mutate(self, info, reminder_id): for topic in topics: try: response = messaging.unsubscribe_from_topic(reminder.fcm_token, topic) + logging.info( + "Unsubscribe %s from %s -> success: %d failure: %d", + reminder.fcm_token[:12], + topic, + response.success_count, + response.failure_count, + ) if response.success_count == 0: raise Exception(response.errors[0].reason) except Exception as error: From e33452c45f238cd77b991e9f5c407f1e0862de4d Mon Sep 17 00:00:00 2001 From: Nicole Qiu Date: Wed, 29 Oct 2025 16:11:39 -0400 Subject: [PATCH 2/3] fix unsubscribe logic for edit and delete capacity --- schema.graphql | 5 +++-- src/schema.py | 13 +++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/schema.graphql b/schema.graphql index 3f1dadd..a161ce6 100644 --- a/schema.graphql +++ b/schema.graphql @@ -40,7 +40,6 @@ type Capacity { type CapacityReminder { id: ID! - fcmToken: String! gyms: [CapacityReminderGym]! capacityThreshold: Int! daysOfWeek: [DayOfWeekEnum]! @@ -227,7 +226,7 @@ type Mutation { createReport(createdAt: DateTime!, description: String!, gymId: Int!, issue: String!): CreateReport deleteUser(userId: Int!): User createCapacityReminder(capacityPercent: Int!, daysOfWeek: [String]!, fcmToken: String!, gyms: [String]!): CapacityReminder - editCapacityReminder(capacityPercent: Int!, daysOfWeek: [String]!, gyms: [String]!, reminderId: Int!): CapacityReminder + editCapacityReminder(daysOfWeek: [String]!, newCapacityThreshold: Int!, newGyms: [String]!, reminderId: Int!): CapacityReminder deleteCapacityReminder(reminderId: Int!): CapacityReminder addFriend(friendId: Int!, userId: Int!): Friendship acceptFriendRequest(friendshipId: Int!): Friendship @@ -274,6 +273,8 @@ type Query { getUserStreak(id: Int!): JSONString getHourlyAverageCapacitiesByFacilityId(facilityId: Int): [HourlyAverageCapacity] getUserFriends(userId: Int!): [User] + getCapacityReminderById(id: Int!): CapacityReminder + getAllCapacityReminders: [CapacityReminder] } type RefreshAccessToken { diff --git a/src/schema.py b/src/schema.py index 4bdffd7..ced6c84 100644 --- a/src/schema.py +++ b/src/schema.py @@ -31,6 +31,11 @@ from firebase_admin import messaging import logging + +def resolve_enum_value(entry): + """Return the raw value for Enum objects while leaving plain strings untouched.""" + return getattr(entry, "value", entry) + # MARK: - Gym @@ -914,7 +919,9 @@ def mutate(self, info, reminder_id, new_gyms, days_of_week, new_capacity_thresho # Unsubscribe from old reminders topics = [ - f"{gym}_{day}_{reminder.capacity_threshold}" for gym in reminder.gyms for day in reminder.days_of_week + f"{resolve_enum_value(gym)}_{resolve_enum_value(day)}_{reminder.capacity_threshold}" + for gym in reminder.gyms + for day in reminder.days_of_week ] for topic in topics: @@ -974,7 +981,9 @@ def mutate(self, info, reminder_id): raise GraphQLError("CapacityReminder not found.") topics = [ - f"{gym}_{day}_{reminder.capacity_threshold}" for gym in reminder.gyms for day in reminder.days_of_week + f"{resolve_enum_value(gym)}_{resolve_enum_value(day)}_{reminder.capacity_threshold}" + for gym in reminder.gyms + for day in reminder.days_of_week ] for topic in topics: From c7a403dcb15f26b081027d01edddc3967ae17161 Mon Sep 17 00:00:00 2001 From: Nicole Qiu Date: Wed, 29 Oct 2025 16:16:56 -0400 Subject: [PATCH 3/3] clean up logs --- src/schema.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/schema.py b/src/schema.py index ced6c84..d17ca30 100644 --- a/src/schema.py +++ b/src/schema.py @@ -928,11 +928,9 @@ def mutate(self, info, reminder_id, new_gyms, days_of_week, new_capacity_thresho try: response = messaging.unsubscribe_from_topic(reminder.fcm_token, topic) logging.info( - "Unsubscribe %s from %s -> success: %d failure: %d", + "Unsubscribe %s from %s", reminder.fcm_token[:12], topic, - response.success_count, - response.failure_count, ) for error in response.errors: logging.warning( @@ -950,11 +948,9 @@ def mutate(self, info, reminder_id, new_gyms, days_of_week, new_capacity_thresho try: response = messaging.subscribe_to_topic(reminder.fcm_token, topic) logging.info( - "Resubscribing %s to %s -> success: %d failure: %d", + "Resubscribing %s to %s", reminder.fcm_token[:12], topic, - response.success_count, - response.failure_count, ) if response.success_count == 0: raise Exception(response.errors[0].reason) @@ -990,11 +986,9 @@ def mutate(self, info, reminder_id): try: response = messaging.unsubscribe_from_topic(reminder.fcm_token, topic) logging.info( - "Unsubscribe %s from %s -> success: %d failure: %d", + "Unsubscribe %s from %s", reminder.fcm_token[:12], topic, - response.success_count, - response.failure_count, ) if response.success_count == 0: raise Exception(response.errors[0].reason)