hngprojects / hng_boilerplate_python_fastapi_web

Apache License 2.0
153 stars 141 forks source link

[FEAT] User Status Filtering for Organizations - BACKEND #52

Open Laban254 opened 1 month ago

Laban254 commented 1 month ago

Description: Implement filtering for members in an organization based on their status (all, members, suspended, left workspace).

Acceptance Criteria:

  1. Filtering:

    • Implement server-side logic to handle filtering members by their status (all, members, suspended, left workspace).
  2. User Preferences:

    • Store members status details securely in the database.
    • Handle member-specific configurations and preferences related to the filtering process.
  3. Error Handling:

    • Log errors for invalid filter requests.
    • Display clear error messages for invalid inputs.
  4. Security Measures:

    • Use HTTPS for secure data transmission.
    • Validate user input on the server side.

Purpose: To filter members securely and efficiently, ensuring accurate and safe members management.

Requirements:

Expected Outcome:

Endpoints:

  1. Fetch members in Organization:

    • Description: Provide a list of members based on filter criteria within a specific organization with pagination support.

    • Endpoint: GET /api/v1/organizations/{organization_id}/members

    • Request Headers:

      • Authorization: Bearer <token> (required)
      • Content-Type: application/json
      • Accept: application/json
    • Request Parameters:

      • status : string (values: members, suspended, left)
      • page: integer (optional, default: 1)
      • limit: integer (optional, default: 10)
    • Request Example:

      
           GET /api/v1/organizations/123/members?status=members&page=1&limit=10 HTTP/1.1
           Host: example.com
           Authorization: Bearer <token>
           Content-Type: application/json
           Accept: application/json
      
      **Response Example:**
    • Response (Success):

      • Status Code: 200 OK
      • Response Body:

        
           {
              "total": "integer",
              "page": "integer",
              "limit": "integer",
              "prev": "string or null",
              "next": "string or null",
              "users": [
                  {
                    "user_id": "string",
                    "organization_id": "string",
                    "user_email": "string",
                    "organization_name": "string"
                 }
              ]
            }
    • Response (No members Found):

      • Status Code: 404 Not Found
      • Response Body:

        
           {
          "message": "No members found",
          "statusCode": 404
          }
    • Response (Invalid Status):

      • Status Code: 400 Bad Request
      • Response Body:

        
        {
          "message": "Invalid status value",
          "statusCode": 400
        }
    • Response (Unauthorized):

      • Status Code: 401 Unauthorized
      • Response Body:

        
        {
          "message": "Unauthorized",
          "statusCode": 401
        }
    • Response (Internal Server Error):

      • Status Code: 500 Internal Server Error
      • Response Body:

        
        {
          "message": "Internal server error",
          "statusCode": 500
        }

Tasks:

Testing:

Laban254 commented 1 month ago

Duplicated from approved Issue: Issue #95

Laban254 commented 1 month ago

slack ID: @kibe