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: Fetch All Subscribers to Newsletter #683

Open
Scepter00 opened this issue Feb 27, 2025 · 0 comments
Open

Feat: Fetch All Subscribers to Newsletter #683

Scepter00 opened this issue Feb 27, 2025 · 0 comments

Comments

@Scepter00
Copy link
Contributor

Description: Fetch All Subscribers to Newsletter API Implementation

Overview:

This API endpoint allows authorized users (e.g., administrators) to retrieve a complete list of subscribers who have signed up for the newsletter. The response will include relevant subscriber details such as email and subscription date, enabling efficient management and communication.

Endpoint Details:

**Method: GET

  • URL: /api/v1/newsletter/subscribers

  • Authentication: Required (JWT token)**

Request Parameters:

  • Optional Query Parameters:

page (integer, optional): Page number for pagination.
size (integer, optional): Number of subscribers per page.

Simplified Sample Request:

GET /api/v1/newsletter/subscribers
Authorization: Bearer <your_jwt_token>
Content-Type: application/json

Responses:

  • 200 OK:
{
  "subscribers": [
    {
      "id": 1,
      "email": "[email protected]",
      "subscribedAt": "2021-01-01T00:00:00Z"
    },
    {
      "id": 2,
      "email": "[email protected]",
      "subscribedAt": "2021-02-15T12:30:00Z"
    }
  ],
  "page": 1,
  "size": 20,
  "totalElements": 150
}

401 Unauthorized:

{
  "error": "User authentication failed. Please provide a valid token."
}

400 Bad Request: (if query parameters are invalid)

{
  "error": "Invalid pagination parameters. Please check your request."
}

500 Internal Server Error:

{
  "error": "An unexpected error occurred while processing your request. Please try again later."
}

Security Considerations:

  • Enforce HTTPS to protect data in transit.
  • Restrict endpoint access to authenticated and authorized users only.
  • Implement rate limiting to prevent abuse of the endpoint.
  • Validate query parameters to ensure robustness.

Implementation Steps:

  1. Authenticate the User:
    Verify the JWT token provided in the request header.

  2. Fetch Subscriber Data:
    Retrieve subscriber records from the database, applying pagination if provided.

  3. Map Data to Response Model:
    Convert database records to a JSON-friendly response model containing subscriber details.

  4. Return Response:
    Send the list of subscribers along with pagination metadata.

  5. Error Handling:
    Handle authentication failures, invalid requests, and unexpected errors appropriately.

Testing:

Unit Tests:
Validate the logic for retrieving subscribers and mapping data correctly.

Integration Tests:
Ensure the endpoint responds with the proper HTTP status codes and payloads under various scenarios (authenticated, unauthorized, invalid parameters, etc.).

Security Tests:
Confirm that only authorized users can access the endpoint and that rate limiting is enforced.

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