boolean-uk / team-dev-server

3 stars 12 forks source link

#42 As a user, so I can interact with others, I want to be able to comment on posts. #244

Closed mnmin closed 1 year ago

mnmin commented 1 year ago

User Story[As a user, so I can interact with others, I want to be able to comment on posts.](https://github.com/boolean-uk/team-dev-requirements/

Tasks

Can add comments on posts up to 150 characters Comments should be displayed most recent first Comments should show the users name and the time the comment was made. Only the first comment is shown by default, along with the number of comments Users can click a "Show all comments" button to expand the list of comments Comments should have smaller font size than posts There should be some kind of "sort by" toggle to sort comments by most recent or oldest

Steps

1) Add a comment model to the Prisma Schema. Comment has one to many relationship with User and Posts. Use the Prisma schema one to many relationships. https://www.prisma.io/docs/concepts/components/prisma-schema/relations/one-to-many-relations

Comment Prisma Schema

2) Add a route “/post/:id/comment” to Post.js file in routers folder.

3) If the user clicks on the comment button, send a POST request to “/post/:id/comment”.

4) Check for validateAuthentication. If the request is successful: return user object with user id. If the request fails, return error message “res, 404, Request authorization to comment on post”.

5) Find the post in the database with the correct ID if not found return error message “ res, 404 “Unable to find the post”.

6) Modify getAll function on the /posts to get all comments with the Post ID and with the userIDs.

7) If the post is found, create a comment with the post ID and comment user ID. If there is an error in creating the comment return error message: “res, 500, “Unable to create comment”

8) Update the post with the comment using prisma schema https://www.prisma.io/docs/concepts/components/prisma-client/crud.

9) Send the response back to the client with the updated post containing the comment, “res, 201”

vherus commented 1 year ago

Brilliant! Approved