Created comment API route, including a patch method for when a comment is added to the array of comments, as well as a delete method.
Created a helper function that will generate a unique ID, this is used in the comment by looking for a post, then being able to detect the comment ID that the user is requesting to delete.
Takes in the user's ID, post's ID, as well as if the comment is being deleted then you will also be required the comment ID
When generating the new comment, the request takes in a JSON that only requires the "comment" field, which will update Firebase DB comment array with that comment alongside an author, comment_id, creation_date, and their username.
AI was used to find a method to create proper formatting for current time that is utilized in creation of the comment, as well as helping create the helper function that generates a unique ID!
How to Test
(Assuming Postman is being used)
Use endpoint including "/api/posts/comment//" to create a new comment
Go to body tab, then click raw, then insert JSON information. For this test, you can just use {"comment": "Any Comment"} as an example
Make sure Postman is set to PATCH request and send request.
If using delete functionality, endpoint would be "/api/posts/comment///"
Make sure Postman is set to DELETE request and send request.
Checklist
[x] I have added/updated relevant documentation, and I have followed the coding style guidelines.
[ ] I have added/updated tests, and I have run the test suite and all tests pass.
[x] I have checked for any potential conflicts with other branches and fixed any merge conflicts.
I reviewed the comment_routes.py file and it looks great! This route will let us add and delete comments, which will let us further develop the comments page in the front end. Great work!
Description / Changes Made
Portions of this code that utilized AI generation
AI was used to find a method to create proper formatting for current time that is utilized in creation of the comment, as well as helping create the helper function that generates a unique ID!
How to Test
(Assuming Postman is being used)
Checklist