Skip to content

Commit

Permalink
Merge pull request #970 from johnson-oragui/fix/newsletter-sunscription
Browse files Browse the repository at this point in the history
fix: Fixed sending of emails to only new newsletter-subscribers.
  • Loading branch information
trevorjob authored Aug 24, 2024
2 parents 2d2fa96 + 11e61f8 commit c71f6dc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
27 changes: 15 additions & 12 deletions api/v1/routes/newsletter.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,23 @@ async def sub_newsletter(
# Save user to the database
NewsletterService.create(db, request)

link = "https://anchor-python.teams.hng.tech/"

# Send email in the background
background_tasks.add_task(
send_email,
recipient=request.email,
template_name="newsletter-subscription.html",
subject="Thank You for Subscribing to HNG Boilerplate Newsletters",
context={"link": link},
)
link = "https://anchor-python.teams.hng.tech/"

# Send email in the background
background_tasks.add_task(
send_email,
recipient=request.email,
template_name="newsletter-subscription.html",
subject="Thank You for Subscribing to HNG Boilerplate Newsletters",
context={"link": link},
)
message = "Thank you for subscribing to our newsletter."
else:
message = "You have already subscribed to our newsletter. Thank you."

return success_response(
message="Thank you for subscribing to our newsletter.",
status_code=status.HTTP_201_CREATED,
message=message,
status_code=status.HTTP_200_OK,
)


Expand Down
11 changes: 8 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ alembic==1.13.2
annotated-types==0.7.0
anyio==4.4.0
astroid==3.2.4
async-timeout==4.0.3
attrs==23.2.0
Authlib==1.3.1
autopep8==2.3.1
Expand All @@ -23,6 +24,7 @@ colorama==0.4.6
cryptography==43.0.0
cssselect==1.2.0
cssutils==2.11.1
Deprecated==1.2.14
dill==0.3.8
distlib==0.3.8
dnspython==2.6.1
Expand All @@ -37,17 +39,18 @@ filelock==3.15.4
flake8==7.1.0
frozenlist==1.4.1
greenlet==3.0.3
slowapi==0.1.9
h11==0.14.0
httpcore==1.0.5
httptools==0.6.1
httpx==0.27.0
identify==2.6.0
idna==3.7
importlib_resources==6.4.4
iniconfig==2.0.0
isort==5.13.2
itsdangerous==2.2.0
Jinja2==3.1.4
limits==3.13.0
lxml==5.2.2
Mako==1.3.5
markdown-it-py==3.0.0
Expand All @@ -61,8 +64,8 @@ nodeenv==1.9.1
packaging==24.1
passlib==1.7.4
pathspec==0.12.1
pillow==10.4.0
pipdeptree==2.23.1
Pillow==10.4.0
platformdirs==4.2.2
pluggy==1.5.0
pre-commit==3.7.1
Expand Down Expand Up @@ -94,9 +97,11 @@ rich==13.7.1
rsa==4.9
shellingham==1.5.4
six==1.16.0
slowapi==0.1.9
sniffio==1.3.1
SQLAlchemy==2.0.31
starlette==0.37.2
stripe==10.7.0
tomli==2.0.1
tomlkit==0.13.0
twilio==9.2.3
Expand All @@ -110,5 +115,5 @@ virtualenv==20.26.3
watchfiles==0.22.0
webencodings==0.5.1
websockets==12.0
wrapt==1.16.0
yarl==1.9.4
stripe==10.7.0

0 comments on commit c71f6dc

Please sign in to comment.