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]: Allow a Q&A community discussion #1182

Open
Black-fox17 opened this issue Mar 1, 2025 · 1 comment
Open

[FEAT]: Allow a Q&A community discussion #1182

Black-fox17 opened this issue Mar 1, 2025 · 1 comment

Comments

@Black-fox17
Copy link

Black-fox17 commented Mar 1, 2025

Community Feature - User Q&A System

Overview

This module implements a comprehensive Q&A system within the platform, enabling users to ask questions, provide answers, and build a knowledge-sharing community. The system supports question resolution, answer acceptance, and proper authorization controls.

Features

  • Question management (create, retrieve, update, delete)
  • Answer management (create, retrieve, update, delete)
  • Content status tracking (resolved questions, accepted answers)
  • User authorization controls
  • Filtering options for questions and answers

Implementation

Services

The system is built around two core services:

CommunityQuestionService

  • Creates, retrieves, updates, and deletes questions
  • Supports filtering questions by various parameters
  • Handles marking questions as resolved/unresolved
  • Manages question ownership and permissions

CommunityAnswerService

  • Creates, retrieves, updates, and deletes answers
  • Fetches answers by question ID or user ID
  • Handles marking answers as accepted/not accepted
  • Ensures only one answer can be accepted per question
  • Manages answer ownership and permissions

API Endpoints

Question Endpoints

POST /community/questions/create
GET /community/questions
GET /community/questions/{question_id}
GET /community/questions/user/{user_id}
PUT /community/questions/{question_id}
PATCH /community/questions/{question_id}/resolve
DELETE /community/questions/{question_id}

Answer Endpoints

POST /community/answers/create
GET /community/answers/question/{question_id}
GET /community/answers/user/{user_id}
PUT /community/answers/{answer_id}
PATCH /community/answers/{answer_id}/accept
DELETE /community/answers/{answer_id}

API Documentation

Question Endpoints

Create a New Question

  • Request Type: POST
  • URL: /community/questions/create
  • Headers:
    {
      "Authorization": "Bearer <your_access_token>",
      "Content-Type": "application/json"
    }
  • Payload:
    {
      "title": "How do I integrate OAuth in FastAPI?",
      "message": "I'm trying to integrate OAuth authentication but facing issues with token validation."
    }
  • Success Response (201):
    {
      "status": "success",
      "status_code": 201,
      "message": "Question created successfully",
      "data": {
        "id": "abc123",
        "title": "How do I integrate OAuth in FastAPI?",
        "message": "I'm trying to integrate OAuth authentication but facing issues with token validation.",
        "user_id": "user123",
        "created_at": "2023-06-15T14:30:00Z",
        "updated_at": "2023-06-15T14:30:00Z",
        "is_resolved": false
      }
    }

Get All Questions

  • Request Type: GET
  • URL: /community/questions
  • Query Parameters:
    • title (optional): Filter questions by title
    • is_resolved (optional): Filter by resolution status
  • Success Response (200):
    {
      "status": "success",
      "status_code": 200,
      "message": "Questions retrieved successfully",
      "data": [
        {
          "id": "abc123",
          "title": "How do I integrate OAuth in FastAPI?",
          "message": "I'm trying to integrate OAuth authentication but facing issues with token validation.",
          "user_id": "user123",
          "created_at": "2023-06-15T14:30:00Z",
          "updated_at": "2023-06-15T14:30:00Z",
          "is_resolved": false
        },
        // More questions...
      ]
    }

Get Question with Answers

  • Request Type: GET
  • URL: /community/questions/{question_id}
  • Success Response (200):
    {
      "status": "success",
      "status_code": 200,
      "message": "Question and answers retrieved successfully",
      "data": {
        "id": "abc123",
        "title": "How do I integrate OAuth in FastAPI?",
        "message": "I'm trying to integrate OAuth authentication but facing issues with token validation.",
        "user_id": "user123",
        "created_at": "2023-06-15T14:30:00Z",
        "updated_at": "2023-06-15T14:30:00Z",
        "is_resolved": false,
        "answers": [
          {
            "id": "ans456",
            "message": "You can use the FastAPI OAuth2 dependency to handle authentication flows.",
            "user_id": "user789",
            "question_id": "abc123",
            "created_at": "2023-06-15T15:20:00Z",
            "updated_at": "2023-06-15T15:20:00Z",
            "is_accepted": false
          }
        ],
        "answer_count": 1
      }
    }

Get User's Questions

  • Request Type: GET
  • URL: /community/questions/user/{user_id}
  • Headers:
    {
      "Authorization": "Bearer <your_access_token>"
    }
  • Success Response (200):
    {
      "status": "success",
      "status_code": 200,
      "message": "Questions for user {user_id} retrieved successfully",
      "data": [
        // List of questions by this user
      ]
    }

Update a Question

  • Request Type: PUT
  • URL: /community/questions/{question_id}
  • Headers:
    {
      "Authorization": "Bearer <your_access_token>",
      "Content-Type": "application/json"
    }
  • Payload:
    {
      "title": "Updated title",
      "message": "Updated message"
    }
  • Success Response (200):
    {
      "status": "success",
      "status_code": 200,
      "message": "Question updated successfully",
      "data": {
        // Updated question data
      }
    }

Mark Question as Resolved

  • Request Type: PATCH
  • URL: /community/questions/{question_id}/resolve
  • Headers:
    {
      "Authorization": "Bearer <your_access_token>"
    }
  • Query Parameters:
    • is_resolved (optional): Boolean flag (default: true)
  • Success Response (200):
    {
      "status": "success",
      "status_code": 200,
      "message": "Question marked as resolved successfully",
      "data": {
        // Updated question data
      }
    }

Delete a Question

  • Request Type: DELETE
  • URL: /community/questions/{question_id}
  • Headers:
    {
      "Authorization": "Bearer <your_access_token>"
    }
  • Success Response (200):
    {
      "status": "success",
      "status_code": 200,
      "message": "Question with ID {question_id} deleted successfully"
    }

Answer Endpoints

Create an Answer

  • Request Type: POST
  • URL: /community/answers/create
  • Headers:
    {
      "Authorization": "Bearer <your_access_token>",
      "Content-Type": "application/json"
    }
  • Payload:
    {
      "question_id": "abc123",
      "message": "You can use the FastAPI OAuth2 dependency to handle authentication flows."
    }
  • Success Response (201):
    {
      "status": "success",
      "status_code": 201,
      "message": "Answer created successfully",
      "data": {
        "id": "ans456",
        "message": "You can use the FastAPI OAuth2 dependency to handle authentication flows.",
        "user_id": "user789",
        "question_id": "abc123",
        "created_at": "2023-06-15T15:20:00Z",
        "updated_at": "2023-06-15T15:20:00Z",
        "is_accepted": false
      }
    }

Get Question Answers

  • Request Type: GET
  • URL: /community/answers/question/{question_id}
  • Success Response (200):
    {
      "status": "success",
      "status_code": 200,
      "message": "Answers retrieved successfully",
      "data": [
        // List of answers for this question
      ]
    }

Get User's Answers

  • Request Type: GET
  • URL: /community/answers/user/{user_id}
  • Headers:
    {
      "Authorization": "Bearer <your_access_token>"
    }
  • Success Response (200):
    {
      "status": "success",
      "status_code": 200,
      "message": "Answers for user {user_id} retrieved successfully",
      "data": [
        // List of answers by this user
      ]
    }

Update an Answer

  • Request Type: PUT
  • URL: /community/answers/{answer_id}
  • Headers:
    {
      "Authorization": "Bearer <your_access_token>",
      "Content-Type": "application/json"
    }
  • Payload:
    {
      "question_id": "abc123",
      "message": "Updated answer content"
    }
  • Success Response (200):
    {
      "status": "success",
      "status_code": 200,
      "message": "Answer updated successfully",
      "data": {
        // Updated answer data
      }
    }

Mark Answer as Accepted

  • Request Type: PATCH
  • URL: /community/answers/{answer_id}/accept
  • Headers:
    {
      "Authorization": "Bearer <your_access_token>"
    }
  • Query Parameters:
    • is_accepted (optional): Boolean flag (default: true)
  • Success Response (200):
    {
      "status": "success",
      "status_code": 200,
      "message": "Answer marked as accepted successfully",
      "data": {
        // Updated answer data
      }
    }

Delete an Answer

  • Request Type: DELETE
  • URL: /community/answers/{answer_id}
  • Headers:
    {
      "Authorization": "Bearer <your_access_token>"
    }
  • Success Response (200):
    {
      "status": "success",
      "status_code": 200,
      "message": "Answer with ID {answer_id} deleted successfully"
    }

Error Responses

Not Found

{
  "detail": "Question with ID {question_id} not found"
}

Unauthorized Access

{
  "detail": "You can only update your own questions"
}

Bad Request

{
  "detail": "Failed to create question: {error_message}"
}

Authorization Rules

  • Users can only update/delete their own questions and answers
  • Only admins can update/delete any question or answer
  • Users can only view their own questions/answers by user ID unless they're admins
  • Only the question owner can mark an answer as accepted

Database Models

CommunityQuestion

  • id: Unique identifier
  • title: Question title
  • message: Question content
  • user_id: ID of the user who asked the question
  • is_resolved: Boolean indicating if the question is resolved
  • created_at: Timestamp of creation
  • updated_at: Timestamp of last update

CommunityAnswer

  • id: Unique identifier
  • message: Answer content
  • user_id: ID of the user who provided the answer
  • question_id: ID of the question this answer belongs to
  • is_accepted: Boolean indicating if this is the accepted answer
  • created_at: Timestamp of creation
  • updated_at: Timestamp of last update

Future Enhancements

  • Add support for tags/categories
  • Implement voting system for answers
  • Add search functionality
  • Add notification system for new answers
  • Implement pagination for questions and answers
@Black-fox17 Black-fox17 changed the title Allow a Q&A community discussion [FEAT]Allow a Q&A community discussion Mar 1, 2025
@Black-fox17 Black-fox17 changed the title [FEAT]Allow a Q&A community discussion [FEAT]: Allow a Q&A community discussion Mar 1, 2025
@Black-fox17
Copy link
Author

@joboy-dev can you revert please?

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