Skip to content

SERVER: Dashboard - Student view - Like post #28

@Kerem-1034003

Description

@Kerem-1034003

Problem Description

As a logged-in user, I want to like or unlike posts,
i also want to know if i already liked a post.
so that I can interact with posts and see the number of likes update in real time.

Required Changes

  • Implement a GET endpoint /posts/{id}/liked to check if the current user already liked.
  • The endpoint should verify that the post exists.
  • Return true if a row exists, otherwise false
  • Implement a POST endpoint /posts/{id}/like to toggle a like on a post.
  • The endpoint should verify that the post exists.
  • The endpoint should return the updated number of likes for the post.

Handle user clicks as follows:

  • Like : insert a new row into the likes table.
  • Unlike: remove the row from the likes table.
  • Like again: insert the row again.

Acceptance Criteria

A user can only have one active like per post at a time.
Toggling works correctly.

Success response:

  • 200 with either the updated post object or { "likes": X }. (POST)
  • 200 with liked = true or liked = false (GET)

Error responses:

  • 404 if post does not exist.
  • 500 for server errors.

Dependencies

  • Database table likes must exist (Database migration issue).
  • Verify the logged-in user.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions