From 44f650f60ec95c37ea54c9bb6806d5ada59af827 Mon Sep 17 00:00:00 2001 From: izzyjosh Date: Tue, 10 Sep 2024 08:31:13 +0100 Subject: [PATCH 1/3] update: added notifying of user when followed or unfollowed --- api/v1/services/user.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/api/v1/services/user.py b/api/v1/services/user.py index eae18d3..77cbdbc 100644 --- a/api/v1/services/user.py +++ b/api/v1/services/user.py @@ -362,6 +362,16 @@ def follow_user(self, db: Session, user_id: str, user: User): if followee not in user.followings: user.followings.append(followee) + notification1 = Notification( + user_id=user.id, message=f"You followed {followee.username}" + ) + notification2 = Notification( + user_id=followee.id, message=f"{user.username} followed you" + ) + + db.add(notification1) + db.add(notification2) + db.commit() def unfollow_user(self, db: Session, user_id: str, user: User): @@ -376,6 +386,17 @@ def unfollow_user(self, db: Session, user_id: str, user: User): ) user.followings.remove(user_to_unfollow) + + notification1 = Notification( + user_id=user.id, message=f"You unfollowed {user_to_unfollow.username}" + ) + notification2 = Notification( + user_id=user_to_unfollow.id, message=f"{user.username} unfollowed you" + ) + + db.add(notification1) + db.add(notification2) + db.commit() def followers(self, db: Session, user: User): From 0e0c2f154cfc6775de909d88ce2d437949e834f9 Mon Sep 17 00:00:00 2001 From: izzyjosh Date: Wed, 11 Sep 2024 16:51:14 +0100 Subject: [PATCH 2/3] fix: correct notification for follow and unfollow --- api/v1/services/user.py | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/api/v1/services/user.py b/api/v1/services/user.py index 77cbdbc..2c59a84 100644 --- a/api/v1/services/user.py +++ b/api/v1/services/user.py @@ -362,16 +362,11 @@ def follow_user(self, db: Session, user_id: str, user: User): if followee not in user.followings: user.followings.append(followee) - notification1 = Notification( - user_id=user.id, message=f"You followed {followee.username}" - ) notification2 = Notification( user_id=followee.id, message=f"{user.username} followed you" ) - db.add(notification1) - db.add(notification2) - + db.add(notification) db.commit() def unfollow_user(self, db: Session, user_id: str, user: User): @@ -387,16 +382,11 @@ def unfollow_user(self, db: Session, user_id: str, user: User): user.followings.remove(user_to_unfollow) - notification1 = Notification( - user_id=user.id, message=f"You unfollowed {user_to_unfollow.username}" - ) - notification2 = Notification( + notification = Notification( user_id=user_to_unfollow.id, message=f"{user.username} unfollowed you" ) - db.add(notification1) - db.add(notification2) - + db.add(notification) db.commit() def followers(self, db: Session, user: User): From 8979320649e868af11179099a6e4d1fdbc1ba378 Mon Sep 17 00:00:00 2001 From: izzyjosh Date: Wed, 11 Sep 2024 17:03:57 +0100 Subject: [PATCH 3/3] fix: corrected error --- api/v1/services/user.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/v1/services/user.py b/api/v1/services/user.py index 2c59a84..7821c65 100644 --- a/api/v1/services/user.py +++ b/api/v1/services/user.py @@ -362,7 +362,7 @@ def follow_user(self, db: Session, user_id: str, user: User): if followee not in user.followings: user.followings.append(followee) - notification2 = Notification( + notification = Notification( user_id=followee.id, message=f"{user.username} followed you" )