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] - ADMIN- implenent get organization owned by a user and organisations a user belongs to #418

Open
lankiman opened this issue Feb 27, 2025 · 0 comments · May be fixed by #428
Open
Assignees
Labels

Comments

@lankiman
Copy link

lankiman commented Feb 27, 2025

Description

Create API endpoints to retrieve two types of organization information for a registered user:

  1. Organizations owned by the user
  2. Organizations the user belongs to (as a member)

These endpoints are part of the administration user management system. They must be secured so that only admin users can access them. Additionally, both endpoints must implement pagination for performance optimization.

Acceptance Criteria

  • Organizations owned by a user:

    • Endpoint: GET /api/v1/admin/users/{id}/organizations/owned
    • Returns a paginated list of organizations that the user owns.
  • Organizations a user belongs to:

    • Endpoint: GET /api/v1/admin/users/{id}/organizations/member
    • Returns a paginated list of organizations that the user is a member of.
  • For both endpoints:

    • Accept HTTP GET requests.
    • Retrieve organizations from the database using the provided user ID.
    • Return a 200 OK status code with the organizations in the response body.
    • Support pagination through query parameters (e.g., page and limit).
    • Be secured and accessible only to an admin user.

API Endpoints

1. Get Organizations Owned by a User

Request

GET api/v1/admin/users/{id}/organizations/owned?offset=1&limit=10

{
  "status_code": 200,
"message": "completed",
"data":{
  "meta": {
    "total_pages": 5,
    "current_page": 1,
    "page_size": 10,
    "total_count": 50,
    "has_previous": false,
    "has_next": true
  },
  "organizations": [
    {
      "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
      "name": "Example Owned Org",
      "description": "Description of the organization",
      "industry": "Tech"
    }
  ]
}
}

{
  "status_code": 404,
  "message": "User not found"
}
{
  "status_code": 400,
  "message": "Valid user ID must be provided"
}

2. Get organizations a user belongs to

Request

GET /api/v1/admin/users/{id}/organizations/member?offset=1&limit=10

{
  "status_code": 200,
   "message": "Request completed successfully",
"data":{
  "meta_data": {
 "total_pages": 5,
    "current_page": 1,
    "page_size": 10,
    "total_count": 50,
    "has_previous": false,
    "has_next": true  },
  "organizations": [
    {
      "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
      "name": "Example Member Org",
      "description": "Description of the organization",
      "industry": "Finance"
    }
  ]
}
}
{
  "status_code": 404,
  "message": "User not found"
}
{
  "status_code": 400,
  "message": "Valid user ID must be provided"
}

Purpose

To provide admin users with detailed organization information about a registered user by retrieving:

  • Organizations the user owns.
  • Organizations the user belongs to as a member.

Requirements

  • Develop server-side logic to retrieve both lists of organizations using the user ID.
  • Securely handle data retrieval and comply with security standards.
  • Validate the user ID and implement pagination using query parameters.

Expected Outcome

The API endpoints will allow admin users to retrieve a user's owned and member organizations with proper validation, pagination, and security measures.

Tasks

Route Definition

  • GET /api/v1/admin/users/{id}/organizations/owned
  • GET /api/v1/admin/users/{id}/organizations/member

Implementation

  • Validate the provided user ID.
  • Retrieve the relevant organizations from the database.
  • Return paginated results using the page and limit query parameters.

Security

  • Ensure endpoints are secured and accessible only to admin users.

Error Handling

  • Return 400 Bad Request if the user ID is missing or invalid.
  • Return 404 Not Found if the user does not exist.

Testing

  • Unit Tests: Validate input, pagination, and data retrieval logic.
  • Integration Tests: Verify end-to-end functionality of the endpoints.
  • Security Tests: Confirm that data protection and access control standards are met.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants