hngprojects / hng_boilerplate_csharp_web

https://api-csharp.boilerplate.hng.tech
Apache License 2.0
78 stars 41 forks source link

[FEAT] Implement API Endpoint for Sending Email Requests #53

Closed ZEEZKING closed 1 month ago

ZEEZKING commented 1 month ago

Description

Develop an endpoint to handle requests for sending emails using pre-defined templates. The emails should be placed in a database queue for sending to ensure the application remains responsive. The endpoint should handle variable substitution, replacing placeholders in the templates with actual data.

Acceptance Criteria

Data Validation

Error Handling

Error Responses: Define error responses for scenarios such as missing template, invalid input, and internal server errors. Edge Cases: Consider edge cases such as template not found, invalid email format, and missing variables.

Performance and Security

Performance Considerations: Ensure the email request queuing system is efficient and does not degrade application performance. Security Concerns: Address security considerations such as data sanitization, input validation, and protection against injection attacks.

Documentation

API Documentation: Provide comprehensive API documentation for the endpoint, including request and response formats. Technical Notes: Include any additional technical notes or considerations for implementing the endpoint.

Testing Requirements

Requirements

[POST] /api/v1/send-email

Description: Enqueues an email request using a specified template.
Request Body:
{
  "template_id": 1,
  "recipient": "john.doe@example.com",
  "variables": {
    "name": "John Doe",
    "product": "Wireless Headphones",
    "order_number": 12345
  }
}
Success Response:
Status Code: 202 Accepted
Body:

{
  "message": "Email sending request accepted and is being processed in the background."
}
Error Responses:
Status Code: 500 Internal Server Error
Body:

{
  "error": "Internal server error."
}
status Code: 404 Not Found
Body:

{
  "error": "Template not found."
}
Status Code: 405 Method Not Allowed
Body:

{
  "error": "This method is not allowed."
}
Status Code: 400 Bad Request
Body:

{
  "error": "An invalid request was sent."
}

Testing

Test Scenarios Successful Email Sending Request

ZEEZKING commented 1 month ago

This issue is linked to the approved issue