@@ -637,14 +637,11 @@ class Query(graphene.ObjectType):
637637 )
638638 get_user_friends = graphene .List (
639639 User , user_id = graphene .Int (required = True ), description = "Get all friends for a user."
640- User , user_id = graphene .Int (required = True ), description = "Get all friends for a user."
641640 )
642641 get_capacity_reminder_by_id = graphene .Field (
643642 CapacityReminder , id = graphene .Int (required = True ), description = "Get a specific capacity reminder by its ID."
644- CapacityReminder , id = graphene .Int (required = True ), description = "Get a specific capacity reminder by its ID."
645643 )
646644 get_all_capacity_reminders = graphene .List (CapacityReminder , description = "Get all capacity reminders." )
647- get_all_capacity_reminders = graphene .List (CapacityReminder , description = "Get all capacity reminders." )
648645
649646 def resolve_get_all_gyms (self , info ):
650647 query = Gym .get_query (info )
@@ -727,23 +724,13 @@ def resolve_get_user_friends(self, info, user_id):
727724 .filter ((FriendshipModel .user_id == user_id ) & (FriendshipModel .is_accepted == True ))
728725 .all ()
729726 )
730- direct_friendships = (
731- Friendship .get_query (info )
732- .filter ((FriendshipModel .user_id == user_id ) & (FriendshipModel .is_accepted == True ))
733- .all ()
734- )
735727
736728 # Reverse friendships where user is the recipient
737729 reverse_friendships = (
738730 Friendship .get_query (info )
739731 .filter ((FriendshipModel .friend_id == user_id ) & (FriendshipModel .is_accepted == True ))
740732 .all ()
741733 )
742- reverse_friendships = (
743- Friendship .get_query (info )
744- .filter ((FriendshipModel .friend_id == user_id ) & (FriendshipModel .is_accepted == True ))
745- .all ()
746- )
747734
748735 friend_ids = set ()
749736 for friendship in direct_friendships :
@@ -755,7 +742,6 @@ def resolve_get_user_friends(self, info, user_id):
755742 # Query for all friends at once
756743 return User .get_query (info ).filter (UserModel .id .in_ (friend_ids )).all ()
757744
758-
759745 @jwt_required ()
760746 def resolve_get_capacity_reminder_by_id (self , info , id ):
761747 reminder = CapacityReminder .get_query (info ).filter (CapacityReminderModel .id == id ).first ()
@@ -765,7 +751,6 @@ def resolve_get_capacity_reminder_by_id(self, info, id):
765751
766752 return reminder
767753
768-
769754 @jwt_required ()
770755 def resolve_get_all_capacity_reminders (self , info ):
771756 query = CapacityReminder .get_query (info )
@@ -1124,9 +1109,39 @@ def mutate(self, info, description, issue, created_at, gym_id):
11241109 report = ReportModel (description = description , issue = issue , created_at = created_at_utc , gym_id = gym_id )
11251110 db_session .add (report )
11261111 db_session .commit ()
1112+
1113+ try :
1114+ sh .worksheet (SHEET_REPORTS ).append_row ([report .id , issue , gym .name , description , created_at .isoformat ()])
1115+ except Exception as e :
1116+ print (f"Error logging report to sheet: { e } " )
1117+
11271118 return CreateReport (report = report )
11281119
11291120
1121+ class DeleteReport (graphene .Mutation ):
1122+ class Arguments :
1123+ report_id = graphene .Int (required = True )
1124+
1125+ Output = Report
1126+
1127+ def mutate (self , info , report_id ):
1128+ # Check if report exists
1129+ report = Report .get_query (info ).filter (ReportModel .id == report_id ).first ()
1130+ if not report :
1131+ raise GraphQLError ("Report with given ID does not exist." )
1132+
1133+ try :
1134+ worksheet = sh .worksheet (SHEET_REPORTS )
1135+ cell = worksheet .find (str (report_id ), in_column = 1 )
1136+ worksheet .delete_rows (cell .row )
1137+ except Exception as e :
1138+ print (f"Error deleting report from sheet: { e } " )
1139+
1140+ db_session .delete (report )
1141+ db_session .commit ()
1142+ return report
1143+
1144+
11301145class DeleteUserById (graphene .Mutation ):
11311146 class Arguments :
11321147 user_id = graphene .Int (required = True )
@@ -1236,7 +1251,6 @@ def mutate(self, info, reminder_id, new_gyms, days_of_week, new_capacity_thresho
12361251 try :
12371252 response = messaging .unsubscribe_from_topic (reminder .fcm_token , topic )
12381253 logging .info ("Unsubscribe %s from %s" , reminder .fcm_token [:12 ], topic )
1239- logging .info ("Unsubscribe %s from %s" , reminder .fcm_token [:12 ], topic )
12401254 for error in response .errors :
12411255 logging .warning (
12421256 "Error unsubscribing %s from %s -> reason: %s" , reminder .fcm_token [:12 ], topic , error .reason
@@ -1253,7 +1267,6 @@ def mutate(self, info, reminder_id, new_gyms, days_of_week, new_capacity_thresho
12531267 try :
12541268 response = messaging .subscribe_to_topic (reminder .fcm_token , topic )
12551269 logging .info ("Resubscribing %s to %s" , reminder .fcm_token [:12 ], topic )
1256- logging .info ("Resubscribing %s to %s" , reminder .fcm_token [:12 ], topic )
12571270 if response .success_count == 0 :
12581271 raise Exception (response .errors [0 ].reason )
12591272 except Exception as error :
@@ -1288,10 +1301,8 @@ def mutate(self, info, reminder_id):
12881301 try :
12891302 response = messaging .unsubscribe_from_topic (reminder .fcm_token , topic )
12901303 logging .info ("Unsubscribe %s from %s" , reminder .fcm_token [:12 ], topic )
1291- logging .info ("Unsubscribe %s from %s" , reminder .fcm_token [:12 ], topic )
12921304 if response .success_count == 0 :
12931305 raise Exception (response .errors [0 ].reason )
1294- raise Exception (response .errors [0 ].reason )
12951306 except Exception as error :
12961307 raise GraphQLError (f"Error unsubscribing from topic { topic } : { error } " )
12971308
@@ -1301,7 +1312,6 @@ def mutate(self, info, reminder_id):
13011312 return reminder
13021313
13031314
1304-
13051315class AddFriend (graphene .Mutation ):
13061316 class Arguments :
13071317 user_id = graphene .Int (required = True )
@@ -1329,14 +1339,6 @@ def mutate(self, info, user_id, friend_id):
13291339 )
13301340 .first ()
13311341 )
1332- existing = (
1333- Friendship .get_query (info )
1334- .filter (
1335- ((FriendshipModel .user_id == user_id ) & (FriendshipModel .friend_id == friend_id ))
1336- | ((FriendshipModel .user_id == friend_id ) & (FriendshipModel .friend_id == user_id ))
1337- )
1338- .first ()
1339- )
13401342
13411343 if existing :
13421344 raise GraphQLError ("Friendship already exists." )
@@ -1349,7 +1351,6 @@ def mutate(self, info, user_id, friend_id):
13491351 return friendship
13501352
13511353
1352-
13531354class AcceptFriendRequest (graphene .Mutation ):
13541355 class Arguments :
13551356 friendship_id = graphene .Int (required = True )
@@ -1393,14 +1394,6 @@ def mutate(self, info, user_id, friend_id):
13931394 )
13941395 .first ()
13951396 )
1396- friendship = (
1397- Friendship .get_query (info )
1398- .filter (
1399- ((FriendshipModel .user_id == user_id ) & (FriendshipModel .friend_id == friend_id ))
1400- | ((FriendshipModel .user_id == friend_id ) & (FriendshipModel .friend_id == user_id ))
1401- )
1402- .first ()
1403- )
14041397
14051398 if not friendship :
14061399 raise GraphQLError ("Friendship not found." )
@@ -1412,7 +1405,6 @@ def mutate(self, info, user_id, friend_id):
14121405 return RemoveFriend (success = True )
14131406
14141407
1415-
14161408class GetPendingFriendRequests (graphene .Mutation ):
14171409 class Arguments :
14181410 user_id = graphene .Int (required = True )
@@ -1432,11 +1424,6 @@ def mutate(self, info, user_id):
14321424 .filter ((FriendshipModel .friend_id == user_id ) & (FriendshipModel .is_accepted == False ))
14331425 .all ()
14341426 )
1435- pending = (
1436- Friendship .get_query (info )
1437- .filter ((FriendshipModel .friend_id == user_id ) & (FriendshipModel .is_accepted == False ))
1438- .all ()
1439- )
14401427
14411428 return GetPendingFriendRequests (pending_requests = pending )
14421429
@@ -1453,7 +1440,6 @@ class Mutation(graphene.ObjectType):
14531440 refresh_access_token = RefreshAccessToken .Field (description = "Refreshes the access token." )
14541441 create_report = CreateReport .Field (description = "Creates a new report." )
14551442 delete_report = DeleteReport .Field (description = "Deletes a report by ID." )
1456- delete_report = DeleteReport .Field (description = "Deletes a report by ID." )
14571443 delete_user = DeleteUserById .Field (description = "Deletes a user by ID." )
14581444 add_friend = AddFriend .Field (description = "Adds a friend to a user." )
14591445 remove_friend = RemoveFriend .Field (description = "Removes a friend from a user." )
@@ -1466,8 +1452,6 @@ class Mutation(graphene.ObjectType):
14661452 get_pending_friend_requests = GetPendingFriendRequests .Field (
14671453 description = "Get all pending friend requests for a user."
14681454 )
1469- description = "Get all pending friend requests for a user."
1470- )
14711455
14721456
14731457schema = graphene .Schema (query = Query , mutation = Mutation )
0 commit comments