Skip to content

Commit

Permalink
Modify unsubscribe functionality at backend (djangoindia#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
prakkhar03 committed Nov 29, 2024
1 parent b4b0679 commit 75bbd4b
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions backend/djangoindia/api/views/communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,13 @@ class UnsubscribeAPIView(generics.GenericAPIView):
def delete(self, request, *args, **kwargs):
try:
email = request.data.get("email")
if not email:
return Response(
{"message": "Email address is required."},
status=status.HTTP_400_BAD_REQUEST,
)
subscriber = Subscriber.objects.filter(email=email).first()
if not subscriber:
if not (email and subscriber):
return Response(
{"message": "No subscription found for this email."},
status=status.HTTP_404_NOT_FOUND,
{"message": "Subscriber not found or Invalid Email"},
status=status.HTTP_400_BAD_REQUEST,
)
subscriber.delete()
subscriber.delete()
return Response(
{"message": "You have been unsubscribed. We're sad to see you go. 😢"},
status=status.HTTP_200_OK,
Expand Down

0 comments on commit 75bbd4b

Please sign in to comment.