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

Jv/add comments likes #144

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

Vrbitko
Copy link

@Vrbitko Vrbitko commented Nov 8, 2022

Description

Added likes and comments models. Implemented tests and added func for admins to delete comment.

References

Fixes # (issue)

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • adding and removing of comments/likes checked manually by calling endpoints
  • implemented tests
  • remove comments on admin side not testes. Just created new method which calls already tested delete_data on Comments model.

Test Configuration:

  • Firmware version: locally run mongoDB 6.0.1, with python version 3.9
  • Os: MacOS Monterey 12.6

Checklist:

  • I have added a description of the change
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented on my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Any dependent changes have been merged and published in downstream modules
  • I have searched previous suggestions before making a new one, as mine may be a duplicate.
  • I acknowledge that all my contributions will be made under the project's license.

@NVombat NVombat linked an issue Nov 8, 2022 that may be closed by this pull request
Comment on lines +168 to +172
{
"error_status": True,
"success_status": False,
"exception": e
},

Check warning

Code scanning / CodeQL

Information exposure through an exception

[Stack trace information](1) flows to this location and may be exposed to an external user.
{
"error_status": True,
"success_status": False,
"exception": e
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revealing the exception data can be a security threat - Better to not disclose exception data

response.JsonResponse
"""
try:
comment = request.query_params.get("comment")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you are expecting a query parameter, have you defined a URL to accept the delete_comment request? Django works on a model-template view basis so you will need to create a view for deleting comments in the views.py and add a URL path for it as well.

@@ -123,3 +123,183 @@ def fetch_data(self) -> response.JsonResponse:
return docs

raise DataFetchingError("There Are No Posts In The Database At This Moment")


class Likes:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To receive the likes, a URL will need to be created along with a view. This will refer to the endpoint that accepts the like and performs the database functionality - It will also update the UI with an increment in the Like Number on the screen.

)

def delete_all_data(self) -> None:
"""Delete all likes from db
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This functionality should only be with the admin - Deleting the data should not be used by any ordinary developer

@@ -12,7 +12,7 @@
InvalidAdminIDError,
)

from . import Paginate, Music_Data, User_Data, Admin_Auth, Admin_Token_Auth
from . import Paginate, Music_Data, User_Data, Admin_Auth, Admin_Token_Auth, Comments
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These dot imports are from the init file - It does not seem like you have added a class so it can be imported

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -123,3 +123,183 @@ def fetch_data(self) -> response.JsonResponse:
return docs

raise DataFetchingError("There Are No Posts In The Database At This Moment")


class Likes:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also add a Dislike option with the same functionality and use flags to decipher which one you are dealing with to prevent code repetition

raise DataFetchingError("There Are No Likes In The Database At This Moment")


class Comments:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the likes - To receive the comments, a URL will need to be created along with a view. This will refer to the endpoint that accepts the comment and performs the database functionality - It will also update the UI with the comment for the client

f"Comment: \n{comment}\ndoes not exists."
)

def delete_all_data(self) -> None:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This functionality should be restricted to the admin only

"""
self.db.remove()

def fetch_data(self) -> response.JsonResponse:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another function can be created to fetch comments for a specific post as well

}
self.db.insert_one(data)

def delete_data(self, comment: str) -> None:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the "comment" field represents the comment ID then where is the comment being stored and if not then the ID is not used or present.

@@ -123,3 +123,183 @@ def fetch_data(self) -> response.JsonResponse:
return docs

raise DataFetchingError("There Are No Posts In The Database At This Moment")


class Likes:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, If you check the user profile, it has a list for contact_us query IDs. Similarly, you should create a list for likes and comments so that we can see which posts a user has liked and commented. This will make user analysis and function handling easier.

None
"""

data = {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe include a comment ID? I can only see a comment field - no ID has been created or stored. Prefix the ID with 'ct'
For example:

ct_153g2e3u0238e0uj

That is an example of the comment ID and like IDs can also be similar

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.

Add Likes & Comments Option For Posts
3 participants