Skip to content

MARISSA MOLEJON | OCT2025-1 | Module-Legacy-Code | Sprint 1 | add unfollow functionality - #6

Open
marissamolejon wants to merge 1 commit into
mainfrom
fix/unfollow
Open

MARISSA MOLEJON | OCT2025-1 | Module-Legacy-Code | Sprint 1 | add unfollow functionality#6
marissamolejon wants to merge 1 commit into
mainfrom
fix/unfollow

Conversation

@marissamolejon

Copy link
Copy Markdown
Owner

Summary

adds the ability to unfollow a user. Following existed;
there was no way to reverse it.

Investigation first

Before writing anything, searched the codebase for existing
"unfollow" references:

This found apiService.unfollowUser(username) already fully written
in front-end/lib/api.mjs, POSTing to /unfollow/<username> — but
no backend route existed, and no UI element called it. This
meant the actual scope of this issue was smaller than it first
appeared: build the missing backend endpoint, and wire up a button —
no new frontend API logic needed.

Backend

  • unfollow(follower, followee) in follows.py — a DELETE,
    naturally idempotent (no UniqueViolation handling needed, unlike
    follow(), since deleting a row that doesn't exist is a no-op).
  • do_unfollow(username) in endpoints.py — takes username from
    the URL path (matching the frontend's existing call and the
    pattern used by other_profile). No request body is sent, so no
    field validation applies.
  • POST /unfollow/<username> route registered in main.py.

Frontend

  • Added an "Unfollow" button to the main profile template (not the
    "Who to follow" suggestion chips — suggested users are, by
    definition, not already followed, so an unfollow button there
    would never apply).
  • createProfile() shows the Unfollow button exactly when
    is_following is true — the inverse of the Follow button's
    existing visibility logic, making the two buttons mutually
    exclusive.
  • New handleUnfollow(), mirroring handleFollow(), calling the
    already-existing apiService.unfollowUser().

Testing

  • Backend (curl): follow → unfollow removes the relationship
    correctly; idempotent re-unfollow attempt succeeds without error;
    unfollowing a nonexistent user returns a 404-style error.
  • Frontend (browser): full Follow → Unfollow → Follow round trip
    verified live on a real profile page — button correctly toggles
    each time, follower counts update correctly in both directions.

Scope

5 files changed, no schema migration needed (uses the existing
follows table). No automated tests added (consistent with prior
PRs in this repo — a good candidate for a follow-up test-coverage
pass across all six issues).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant