Skip to content

Commit

Permalink
feat: added follow and unfollow notification (#74)
Browse files Browse the repository at this point in the history
#### Related Issue (Link to issue ticket)
---

#73 

#### Description
---

<!--- Describe your changes in detail -->


#### Context
---

<!--- Why is this change required? What problem does it solve? -->

​

#### How Has This Been Tested? Screenshots (if appropriate - Postman,
etc)
---

- pytest

#### Types of changes
---

<!--- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
      ​

#### Checklist:
---

<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->

- [x]  My code follows the code style of this project.
- [x] I have read the **CONTRIBUTING** document.
- [x] I have added tests to cover my changes.
- [x] All new and existing tests passed.
  • Loading branch information
codewitgabi authored Sep 11, 2024
2 parents de797ca + 8979320 commit 1f91df6
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions api/v1/services/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,11 @@ def follow_user(self, db: Session, user_id: str, user: User):
if followee not in user.followings:
user.followings.append(followee)

notification = Notification(
user_id=followee.id, message=f"{user.username} followed you"
)

db.add(notification)
db.commit()

def unfollow_user(self, db: Session, user_id: str, user: User):
Expand All @@ -376,6 +381,12 @@ def unfollow_user(self, db: Session, user_id: str, user: User):
)

user.followings.remove(user_to_unfollow)

notification = Notification(
user_id=user_to_unfollow.id, message=f"{user.username} unfollowed you"
)

db.add(notification)
db.commit()

def followers(self, db: Session, user: User):
Expand Down

0 comments on commit 1f91df6

Please sign in to comment.