Skip to content

Commit

Permalink
feat: refactor notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhruv9449 committed Apr 27, 2024
1 parent 32d90bd commit 2d91e49
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from rest_framework_simplejwt.authentication import JWTAuthentication

from student_welfare_backend.customs.permissions import IsDSW, IsADSW
from student_welfare_backend.core.utils.notifications import send_notification
from student_welfare_backend.core.tasks.notifications import send_notification


class PushNotificationView(APIView):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.core.management.base import BaseCommand
from student_welfare_backend.core.utils.notifications import send_notification
from student_welfare_backend.core.tasks.notifications import send_notification


class Command(BaseCommand):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
firebase_app = firebase_admin.initialize_app(cred)


def get_title(event: Event):
return f"Register for {event.name} by {event.organization.name} on VTOP now!"

@app.task(name="send_notification")
def send_notification(title, body, topic, image_url=None):
message = messaging.Message(
Expand All @@ -20,10 +23,11 @@ def send_notification(title, body, topic, image_url=None):


@app.task(name="send_event_notification")
def send_event_notification(event: Event, body: str):
title = event.title
def send_event_notification(event: Event):
title = get_title(event)
topic = f"{event.organization.name}"
image_url = event.poster_link
body = event.description
send_notification(title, body, topic, image_url)


Expand Down

0 comments on commit 2d91e49

Please sign in to comment.