-
-
Notifications
You must be signed in to change notification settings - Fork 61
West Midlands | 26 March SDC | Iswat Bello | Sprint 1 | Purple Forest/New Feature/Unfollow #227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Iswanna
wants to merge
2
commits into
CodeYourFuture:main
Choose a base branch
from
Iswanna:new-feature/unfollow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+80
−3
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # Project Log: PurpleForest - Un-follow Feature Implementation | ||
|
|
||
| ## 1. Feature Overview | ||
| Developed the "Un-follow" functionality to allow users to stop seeing blooms from specific accounts. This required building a "Reverse Path" that mirrors the "Follow" logic but executes a deletion in the database. | ||
|
|
||
| --- | ||
|
|
||
| ## 2. Structural Changes | ||
|
|
||
| ### A. Database Layer (The Memory) | ||
| * **Logic:** Implemented the removal of data using the SQL `DELETE` command. | ||
| * **Precision:** Used a `WHERE` clause targeting both the `follower` and the `followee` IDs. | ||
| * **The "Why":** This ensures the operation only removes the specific relationship between two users without accidentally deleting all follows for a single user. | ||
|
|
||
| ### B. Backend Layer (The Brain) | ||
| * **Data Logic (`data/follows.py`):** | ||
| * Created the `unfollow` function. | ||
| * Used **parameterized queries** with a dictionary to safely pass user IDs to the database driver. | ||
| * **API Endpoint (`endpoints.py`):** | ||
| * Developed the `do_unfollow` controller. | ||
| * **Contract Matching:** Designed the function to accept `target_username` directly from the URL path to stay consistent with the existing Frontend API service. | ||
| * **Security:** Applied the `@jwt_required` middleware to ensure only the authenticated account owner can modify their following list. | ||
| * **Routing (`main.py`):** Registered the new `/unfollow/<target_username>` route and imported the necessary logic from the endpoints module. | ||
|
|
||
| ### C. Frontend Layer (The Face) | ||
| * **Visibility Logic (`profile.mjs`):** | ||
| * Modified the `createProfile` component to prevent the button from being hidden when a user is already followed. | ||
| * **The Toggle:** Implemented an `if/else` block to dynamically change the button text between "Follow" and "Un-follow" based on the `is_following` state. | ||
| * **Event Handling (`profile.mjs`):** | ||
| * Upgraded the `handleFollow` function into a **"Smart Switch."** | ||
| * **The Logic:** The handler now inspects the current text of the button. If it says "Un-follow," it calls the `unfollowUser` API; otherwise, it calls the standard `followUser` API. | ||
|
|
||
| --- | ||
|
|
||
| ## 4. Verification & Testing | ||
| * **Action Verification:** Confirmed that clicking "Follow" changes the UI to "Un-follow" and vice-versa. | ||
| * **Data Integrity:** Used **DBeaver** to verify that the corresponding row in the `follows` table is physically removed upon clicking "Un-follow." | ||
| * **Social Feed Test:** Verified that un-following a user immediately stops their posts from appearing in the Home timeline upon the next refresh. | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your "Smart Switch" works, and I like that you found a single handler for both directions. One thing to chew on — no change needed here, just a thought for future you: the handler decides which API to call by reading the button's visible text,
button.textContent === "Un-follow". That quietly ties your logic to whatever the label happens to say. What do you think would happen to thisifif someone later renamed the button to "Unfollow" (no hyphen), translated the page, or dropped an icon inside the button?You already hold the real answer to "am I following this person?" in your data —
profileData.is_following. Is there a way you could branch on that state instead of the on-screen wording? Something to explore when you're curious, not to change for this PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback. In the future, I'll try to use the data state (like a data-following attribute) to drive the logic so the frontend logic doesn't have to rely on what the UI is showing. Thanks for the suggestion.