Skip to content
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

[FEAT]: Endpoint To Delete Blog Like #965

Open
9 tasks
chimeziriobioha opened this issue Aug 24, 2024 · 0 comments
Open
9 tasks

[FEAT]: Endpoint To Delete Blog Like #965

chimeziriobioha opened this issue Aug 24, 2024 · 0 comments

Comments

@chimeziriobioha
Copy link
Contributor

chimeziriobioha commented Aug 24, 2024

Description:

Implement an endpoint to enable users who previously liked a blog post to remove the like.

Acceptance Criteria:

  • It should be a PROTECTED endpoint, requiring authentication.
  • It should be a DELETE request at /api/v1/blogs/likes/{blog_like_id}.
  • It should remove BlogLike from the database and return appropriate message to the user.
  • It should allow ONLY the user who posted the like to delete it.

Purpose

To enable a blog post readers to remove like from any particular post after adding one.

Requirements

  • Develop server-side logic to delete like from a blog post following acceptance criteria above
  • Test the endpoint for correctness and accuracy.

Expected Outcome:

Blog readers should be able to remove like from a blog post if they posted it in error or just changed their mind.


Tasks:

  • Create endpoint (DELETE: /api/v1/blogs/likes/{blog_like_id}) to handle request.
  • Validate blog_like_id, access BlogLike object and confirm that requester created it.
  • Delete the BlogLike object from the database
  • Return self explanatory success response if request goes well, or failure response, if it doesn't.
  • Write comprehensive unit tests for the endpoint and operation.

Example Request [With Auth Token]:

curl -X DELETE {rootdomain}/api/v1/blogs/likes/{blog_like_id} \
     -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
     -d ....

Response Body [Success]:

status_code: 204

Response Body [Errors]:

  • Unrecognized user: { "status_code": 401, "message": "Could not validate credentials." }
  • Not the blog like owner: { "status_code": 401, "message": "Insufficient permission" }
  • Invalid blog ID: { "status_code": 404, "message": "BlogLike does not exist." }***

Testing:

  • Write end-to-end backend unit tests for the delete blog like process.
  • Test all possible outcomes and reactions for like (e.g., successful, failed, etc).

Added Fix:

Enable /api/v1/blogs/{blog_id}/like endpoint to automatically remove existing dislike by the current_user before creating new like, and vice versa with the /api/v1/blogs/{blog_id}/dislike endpoint.

This is important if a user clicks the like button after already clicking the dislike button without first removing the dislike. Otherwise, the database will have unintended records of both like and dislike for the same user on the same blog

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

No branches or pull requests

1 participant