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
[x] Implement API endpoint with data validation and sanitization
[x] 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
Unit Tests
The systems should have unit tests covering:
[x] Validates User's email and check for duplicate emails.
[x] Ensure data is saved correctly to the database.
[ ] Test that the appropriate response and status code is returned
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
[x] Implement API endpoint with data validation and sanitization
[x] 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
Responses:
Successful response
Error response
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
The systems should have unit tests covering:
[x] Validates User's email and check for duplicate emails.
[x] Ensure data is saved correctly to the database.
[ ] Test that the appropriate response and status code is returned