Skip to content

feat(faq-inquiries): Add user association and delete functionality #1153

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

Open
wants to merge 13 commits into
base: dev
Choose a base branch
from

Conversation

SamuelOshin
Copy link

Delete FAQ and Add User ID to FAQ

Description

This PR implements two changes:

  1. Delete FAQ: Adds functionality to allow users to delete FAQ entries.
    DELETE /api/v1/faq-inquiries/{id}
  2. Add User ID to FAQ: Modifies the FAQ model to include a user_id field, ensuring FAQs are associated with a specific user.

Related Issue (Link to issue ticket)

Motivation and Context

  • The Delete FAQ feature allows users to remove outdated or incorrect FAQ entries, improving data management.
  • The Add User ID to FAQ ensures that FAQs are linked to the user who created them, enabling better access control and accountability.

How Has This Been Tested?

  • Implemented unit tests for both features.
  • Verified deletion functionality using Postman to ensure correct HTTP responses.
  • Tested database migrations and API responses to confirm user_id is correctly stored and retrieved.
  • Checked role-based access control for FAQ deletion to prevent unauthorized removals.

Screenshots (if appropriate - Postman, etc):

dELETE FAQ image

Types of changes

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

SamuelOshin and others added 8 commits February 28, 2025 22:07
… FAQ inquiries, added tests for the delete endpoint
… the faq_inquiries

Added a mock JWT token for Bearer authentication in test requests

Updated `AUTH_HEADERS` to include the mock token

Ensured the token is used in POST `/faq-inquiries` and `DELETE /faq-inquiries/{id}` tests

Improved test reliability by simulating authenticated requests
Copy link
Contributor

@joboy-dev joboy-dev left a comment

Choose a reason for hiding this comment

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

Why do you think attaching user id to faq is a good idea??

@SamuelOshin
Copy link
Author

can i modify the middleware in this format to allow public routes that doesn't need token ???

class UserMiddleware(BaseHTTPMiddleware):
    async def dispatch(self, request: Request, call_next):
        db = next(get_db())
        access_token = request.headers.get("Authorization")

        if access_token:  # Only check if a token is provided
            request.state.current_user = await user_service.get_current_user_or_none(access_token, db)
        else:
            request.state.current_user = None  # Allow anonymous users

        response = await call_next(request)
        return response

@joboy-dev
Copy link
Contributor

There's no need for that Middleware in the first place
Thats why we use dependencies

@SamuelOshin
Copy link
Author

There's no need for that Middleware in the first place
Thats why we use dependencies
Okay I'll make changes and use Depends()

@SamuelOshin
Copy link
Author

Hi joedev i have made use of dependency and removed the middleware
thanks

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.

2 participants