mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-15 18:07:02 +00:00
43 lines
1.5 KiB
Python
43 lines
1.5 KiB
Python
"""
|
|
notifications views file
|
|
"""
|
|
# django imports
|
|
from django.db.models import Q
|
|
from rest_framework import viewsets
|
|
from rest_framework.decorators import action
|
|
from rest_framework.permissions import IsAuthenticated
|
|
from rest_framework.response import Response
|
|
|
|
# local imports
|
|
from account.utils import custom_response
|
|
from base.messages import SUCCESS_CODE
|
|
from notifications.constants import TEST_NOTIFICATION
|
|
from notifications.serializers import RegisterDevice
|
|
from notifications.utils import send_notification
|
|
|
|
|
|
class NotificationViewSet(viewsets.GenericViewSet):
|
|
""" used to do the notification actions """
|
|
serializer_class = RegisterDevice
|
|
permission_classes = [IsAuthenticated, ]
|
|
|
|
@action(methods=['post'], detail=False, url_path='device', url_name='device', serializer_class=RegisterDevice)
|
|
def fcm_registration(self, request):
|
|
"""
|
|
used to save the fcm token
|
|
"""
|
|
serializer = self.get_serializer_class()(data=request.data,
|
|
context={'user_id': request.auth.payload['user_id']})
|
|
serializer.is_valid(raise_exception=True)
|
|
serializer.save()
|
|
return custom_response(SUCCESS_CODE["3000"])
|
|
|
|
@action(methods=['get'], detail=False, url_path='test', url_name='test')
|
|
def send_test_notification(self, request):
|
|
"""
|
|
to send test notification
|
|
:return:
|
|
"""
|
|
send_notification.delay(TEST_NOTIFICATION, None, request.auth.payload['user_id'], {})
|
|
return custom_response(SUCCESS_CODE["3000"])
|