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: newsletter's unsubscribe endpoint #421

Closed

Conversation

Heba-WebDev
Copy link
Contributor

Description

Closes #404

Changes proposed

  • Added POST /api/v1/news-letter/unsubscribe endpoint to Newsletter controller
  • Created a command and a command handler in the Hng.Application project to handle the interface and logic of the endpoint
  • Added unit tests for the command handler in the Hng.Application.Test project

Check List (Check all the applicable boxes)

  • My code follows the code style of this project.
  • This PR does not contain plagiarized content.
  • The title and description of the PR is clear and explains the approach.
  • I am making a pull request against the dev branch (left side).
  • My commit messages styles matches our requested structure.
  • My code additions will fail neither code linting checks nor unit test.
  • I am only making changes to files I was requested to.

Screenshots/Videos

  • Invalid email format returns a 400 status code
    Screenshot 2025-02-27 at 11 04 27 PM

  • Not found subscriber return 400 status code
    Screenshot 2025-02-27 at 11 03 13 PM

  • Successful response returns a 200 status code
    Screenshot 2025-02-27 at 11 04 12 PM

  • Tests passed
    Screenshot 2025-02-27 at 10 54 18 PM

@samuelogboye
Copy link

Is there a subscribe endpoint?

@Heba-WebDev
Copy link
Contributor Author

Heba-WebDev commented Feb 27, 2025

Yes, the subscribe endpoint is POST /api/v1/pages/newsletter. (On the issue I had PATCH as the method, but I changed it to POST to match what the other teams have)

@samuelogboye
Copy link

if Subscribe is /api/v1/news-letter POST
unsubscribe should be /api/v1/news-letter DELETE

@Heba-WebDev
Copy link
Contributor Author

Heba-WebDev commented Feb 27, 2025

The dilemma is, we're asked to have a unified backend.

  • Py team: have an identical endpoint to this one.
    pros: no need to call a GET endpoint to get the id
    cons: DELETE method is more accurate.
  • Nestjs team: have DELETE /:id endpoint.
    pros: DELETE method is accurate.
    cons: the client now needs to call a GET endpoint to find the id and then call the DELETE endpoint.

What approach would be considered more RESTful? I'd like to know your opinion.

@samuelogboye
Copy link

.../news-letter POST for subscribe (add resource to db)
.../news-letter DELETE for unsubscribe (remove from db)

this is more RESTFUL

}

var subscriber = await _repository.GetBySpec(
s => s.Email == request.SubscriptionDto.Email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use .Trim().ToLower() to normalize the email before processing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted

@samuelogboye
Copy link

Whats your thought on soft and hard delete?

@Heba-WebDev
Copy link
Contributor Author

Both are needed, though soft delete is more common (for marketing, for archiving, for legal purposes etc).

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

Successfully merging this pull request may close these issues.

[FEAT] Implement Unsubscribe Endpoint for Newsletter
2 participants