32 lines
955 B
Python
32 lines
955 B
Python
|
|
from rest_framework.permissions import IsAuthenticated
|
||
|
|
from rest_framework.response import Response
|
||
|
|
from rest_framework.views import APIView
|
||
|
|
|
||
|
|
from apps.notifications.services import NotificationService
|
||
|
|
|
||
|
|
from .serializers import NotificationListSerializer
|
||
|
|
|
||
|
|
|
||
|
|
class NotificationListView(APIView):
|
||
|
|
permission_classes = [IsAuthenticated]
|
||
|
|
|
||
|
|
def get(self, request):
|
||
|
|
data = NotificationService.list_for_user(request.user)
|
||
|
|
return Response(NotificationListSerializer(data).data)
|
||
|
|
|
||
|
|
|
||
|
|
class NotificationMarkReadView(APIView):
|
||
|
|
permission_classes = [IsAuthenticated]
|
||
|
|
|
||
|
|
def post(self, request, notification_id):
|
||
|
|
NotificationService.mark_read(request.user, notification_id)
|
||
|
|
return Response({"success": True})
|
||
|
|
|
||
|
|
|
||
|
|
class NotificationMarkAllReadView(APIView):
|
||
|
|
permission_classes = [IsAuthenticated]
|
||
|
|
|
||
|
|
def post(self, request):
|
||
|
|
NotificationService.mark_all_read(request.user)
|
||
|
|
return Response({"success": True})
|