Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
QA2A committed Aug 15, 2024
1 parent 8a0a173 commit bef392d
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions website/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,27 @@ def get_queryset(self):
return Profile.objects.filter(is_public=True).order_by("-web_views")


import re

from rest_framework import status
from rest_framework.exceptions import ValidationError
from rest_framework.response import Response
from rest_framework.views import APIView


class BouncedEmailAPI(APIView):
permission_classes = [IsAuthenticated]
parser_classes = [MultiPartParser, FormParser]

def post(self, request, *args, **kwargs):
# Extract email and reason from the request.POST (form data)
email = request.POST.get("email")
reason = request.POST.get("reason")
# Use request.data to get the POST data
email = request.data.get("email")
reason = request.data.get("reason")

if not email:
raise ValidationError({"email": "This field is required."})
if not reason:
raise ValidationError({"reason": "This field is required."})

# Check if email is valid
if not re.match(r"[^@]+@[^@]+\.[^@]+", email):
raise ValidationError({"email": "Invalid email address."})
Expand All @@ -106,7 +114,7 @@ def post(self, request, *args, **kwargs):
).first()

if not application:
return JsonResponse(
return Response(
{"detail": "No active application found for this company."},
status=status.HTTP_404_NOT_FOUND,
)
Expand All @@ -117,7 +125,7 @@ def post(self, request, *args, **kwargs):
)

if not created:
return JsonResponse(
return Response(
{"detail": "Bounced email entry already exists."},
status=status.HTTP_409_CONFLICT,
)
Expand All @@ -127,14 +135,13 @@ def post(self, request, *args, **kwargs):
company.email = ""
company.save()

return JsonResponse(
{
"detail": "Bounced email processed successfully."
},
return Response(
{"detail": "Bounced email processed successfully."},
status=status.HTTP_201_CREATED,
)



@login_required
def application_count(request):
# Get the current time
Expand Down

0 comments on commit bef392d

Please sign in to comment.