Skip to content

[FEAT]: NewsLetter Page Api Endpoint - BACKEND #46

Open
@Solomonuche

Description

@Solomonuche

Description

Develop a backend endpoint to handle requests for newsletter subscriptions. The endpoint will accept an email address, validate and sanitize it, and then handle both successful and failed validations appropriately. If the email passes validation, it will be stored in the database and a 'success' response will be sent to the client. If validation fails, an error message will be returned.

Acceptance Criteria

  • Accepts and validates User's email.
  • Persist the data to the database.
  • Return the appropriate response and status code

Requirements

  • Implement API endpoint with data validation and sanitization
  • Set up database integration and secure storage
  • Integrate email service for confirmation messages

Expected Outcome

  • The user input data should be successfully sent to the backend, or the user will receive an error message if unsuccessful

Status code

  • 201: Email was successfully stored.
  • 400: Invalid email address.
  • 401: Email already exist.
  • 500: A server error occurred.

Endpoint

[POST] /api/v1/pages/newsletter

Requests:

headers:

  • content-type: application/json
{
    "email": "string"
}

Responses:

Successful response

{
    "message": "string",
    "success": true,
    "status_code": int
}

Error response

{
    "message": "string",
    "success": false,
    "status_code": int
}

Database design

schema

Table name: subscribers_table

id:

  • constraints: string(uuid), unique, primary-key, not null

email:

  • constraints: string, unique, not null, length(150)

createdAt:

  • constraints: string, date timestamp

Testing

  1. Unit Tests

The systems should have unit tests covering:

  • Validates User's email and check for duplicate emails.
  • Ensure data is saved correctly to the database.
  • Test that the appropriate response and status code is returned

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

In Implementation

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions