from django.http.response import JsonResponse
from rest_framework.views import APIView
from rest_framework.permissions import IsAuthenticated

from .models import *

from Subscriptions.serializers import NotificationSerializer

from N3wtSchool import bdd

class NotificationView(APIView):
    permission_classes = [IsAuthenticated]

    def get(self, request):
        # Filtrer les notifications de l'utilisateur authentifié uniquement (protection IDOR)
        notifsList = Notification.objects.filter(user=request.user)
        notifs_serializer = NotificationSerializer(notifsList, many=True)

        return JsonResponse(notifs_serializer.data, safe=False)